Sharepoint 2010 以编程方式开始在Sharepoint 2010中对给定内容源进行爬网

Sharepoint 2010 以编程方式开始在Sharepoint 2010中对给定内容源进行爬网,sharepoint-2010,Sharepoint 2010,是否可以通过Sharepoint API或任何其他方式以编程方式开始对给定的内容源(例如文件共享)进行爬网?根据Rob上面的评论,我发现这很有帮助。下面是我编写的C#代码 如果您正在构建控制台应用程序,则链接中的代码会在SPServiceContext.Current上引发错误。因此,第一步和GetContext()方法是特定于这种情况的 SPSite mySite = new SPSite("http://localhost"); SearchServiceAp

是否可以通过Sharepoint API或任何其他方式以编程方式开始对给定的内容源(例如文件共享)进行爬网?

根据Rob上面的评论,我发现这很有帮助。下面是我编写的C#代码

如果您正在构建控制台应用程序,则链接中的代码会在SPServiceContext.Current上引发错误。因此,第一步和GetContext()方法是特定于这种情况的

SPSite mySite = new SPSite("http://localhost");
                SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(mySite));                     Guid appId = proxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;

                //Console.WriteLine("AppID : " + appId.ToString());

                SearchServiceApplication app = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(appId);
                Content content = new Content(app);

                ContentSourceCollection cs = content.ContentSources;
                Console.WriteLine("Name\tId\tCrawlCompleted");
                foreach (ContentSource csi in cs)
                {
                    Console.WriteLine(csi.Name + "\t" + csi.Id + "\t" + csi.CrawlCompleted);
                }

                Console.WriteLine("Starting full crawl....");

                ContentSource css = content.ContentSources["source name"]; //csi.Name within square brackets
                css.StartFullCrawl();

                Console.WriteLine("Full crawl on source name started...");
SPSite mySite=新的SPSite(“http://localhost");
SearchServiceApplicationProxy=(SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(mySite));Guid appId=proxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;
//Console.WriteLine(“AppID:+AppID.ToString());
SearchServiceApplication app=SearchService.Service.SearchApplications.GetValue(appId);
内容=新内容(应用程序);
ContentSourceCollection cs=content.ContentSources;
Console.WriteLine(“Name\tId\tCrawlCompleted”);
foreach(cs中的ContentSource csi)
{
Console.WriteLine(csi.Name+“\t”+csi.Id+“\t”+csi.crawlingcompleted);
}
Console.WriteLine(“开始完全爬网…”);
ContentSourceCSS=content.ContentSources[“源名称”]//csi.方括号内的名称
css.StartFullCrawl();
WriteLine(“已开始对源名称进行完全爬网…”);

确保在Sharepoint安装的项目属性中调整生成目标平台。否则,将不会创建SpSite

我发现了这个问题,如果其他人也在寻找同样的问题。但我不明白如何采用它来使用文件共享而不是业务数据内容源。谢谢你,罗布!我明天会检查这个,然后把结果贴在这里。