I have to read Shared Documents from all sites/subsites of Sharepoint in my Console application which will run on the same machine where Sharepoint is installed but it will be based on .Net Framework 4.0. I believe, Sharepoint Server Objects is based on Framework 3.5 so I came up with idea to create my custom web service which read and return list of documents. I created my custom Service as mentiond in this blog and it is working fine. Here is my code to read the documents in one of my web service method.
SPWebApplication webApp = SPContext.Current.Site.WebApplication;
#region Traverse all sub sites
foreach (SPSite subSite in webApp.Sites)
{
using (SPWeb sWeb = subSite.OpenWeb())
{
foreach (SPList list in sWeb.Lists)
{
if (list.BaseType == SPBaseType.DocumentLibrary &&
list.Hidden == false && list.BaseTemplate == SPListTemplateType.DocumentLibrary &&
list.Title.Equals("Style Library", StringComparison.InvariantCultureIgnoreCase) == false &&
list.Title.Equals("Site Assets", StringComparison.InvariantCultureIgnoreCase) == false)
But as soon as I reach on following line "foreach (SPList list in sWeb.Lists)" it throw exception of type "'System.Threading.ThreadAbortException'"
Even if I try to get the Lists count above this foreach loop sWeb.Lists.count, it still throw the same exception. Please help me what I am doing wrong here?