/// Выдаёт все библиотеки документов
/// </summary>
/// <returns>очередную библиотеку </returns>
/// <remarks>вызывать в цикле вида
/// foreach (SPDocumentLibrary lib in DocLibs()){ ... }
/// </remarks>
IEnumerable< SPDocumentLibrary>DocLibs() {
SPGlobalAdmin ga = new SPGlobalAdmin();
string[] vsNames = ga.VirtualServerNames;
for(int vs=0;vs<vsNames.Length;vs++){
SPVirtualServer srv = null;
try {
srv = ga.VirtualServers[vs];
} catch (Exception err) {
log.WriteException(err, false, vsNames[vs], 68);
continue;//next VirtualServer
}
int nSites = -1;
try {
nSites = srv.Sites.Count;
} catch { }
if (nSites > 0) {
string[] siteNames = new string[srv.Sites.Count];
for (int s = 0; s < siteNames.Length; s++)//fill names
try {
siteNames[s] = srv.Sites[s].Url;
} catch {
siteNames[s] = null;
}
foreach (string siteName in siteNames) {
if (string.IsNullOrEmpty(siteName)) continue; //next Site
SPSite site = null;
try {
site = new SPSite(siteName);
} catch (Exception err) {
log.WriteException(err, false, siteName, 69);
continue; //next Site
}
site.CatchAccessDeniedException = false;
string[] webNames;
try {
webNames = site.AllWebs.Names;
} catch (Exception err) {
log.WriteException(err, false, siteName, 691);
continue; //next Site
}
foreach (string webUrl in webNames) {
SPWeb web = null;
try {
web = site.AllWebs[webUrl];
} catch (Exception err) {
log.WriteException(err, false, webUrl, 70);
continue;//next web
}
int listsCount=-1;
try {
listsCount=web.Lists.Count;
} catch { }
if (listsCount > 0) {
string[] listNames = new string[listsCount];
for (int l = 0; l < listsCount; l++) {
try {
listNames[l] = web.Lists[l].Title;
} catch (Exception err) {
log.WriteException(err, false,
string .Format("List number {0}", l + 1), 71);
listNames[l] = string.Empty;
}
}
foreach (string listName in listNames) {
if (!string.IsNullOrEmpty(listName)) {
SPList list = null;
try {
list = web.Lists[listName];
} catch (Exception err) {
log.WriteException(err, false, listName, 72);
continue; //next List
}
if (list != null && list is SPDocumentLibrary)
yield return list as SPDocumentLibrary;
}
}
}
web.Dispose(); }
site.Dispose(); }
}
}
ga.Dispose();
}