简体   繁体   English

如何使用C#连接到SharePoint 2007?

[英]How to connect to SharePoint 2007 using C#?

I have a SharePoint 2007 farm and I need to connect to it using C# in order to get its data programmatically. 我有一个SharePoint 2007服务器场,我需要使用C#连接到它,以便以编程方式获取其数据。

The purpose of all this is to get all its lists (including fields and data) and subsites in order to recreate them in SharePoint Online. 所有这些操作的目的是获取其所有列表(包括字段和数据)和子网站,以便在SharePoint Online中重新创建它们。 I successfully connected to SPO, but to SharePoint 2007 I could not. 我已成功连接到SPO,但无法连接到SharePoint 2007。

using (SPSite site = new SPSite(root_url + "/" + relative_site_url))
                        {
                            using (SPWeb web = site.OpenWeb())
                            {
                                //SPFolder myLibrary = web.Folders["testdocuments"];
                                SPWebCollection SitesList = web.Site.AllWebs;
                                int i = 0;
                                foreach (string WebSiteName in SitesList.Names)
                                {
                                    if (WebSiteName.Contains(relative_site_url))
                                    {
                                        //Console.WriteLine("Title: " + WebSite.Title);
                                        //Console.WriteLine("Description: " + WebSite.Description);
                                        Console.WriteLine(i.ToString() + " " + WebSiteName);
                                        Console.WriteLine("Lists:");
                                        GetSiteLists(root_url + "/" + relative_site_url);
                                        i++;
                                    }
                                }
                            }
                        }
        }

I am expecting a successful connection. 我期望连接成功。 However, I got this error message when trying to connect to a local SharePoint 2007: 但是,尝试连接到本地SharePoint 2007时收到以下错误消息:

Unhandled Exception: System.IO.FileNotFoundException: The Web application at http://localhost/ could not be
 found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administ
rator may need to add a new request URL mapping to the intended application.
   at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
   at ExportSolution.Program.GetSiteLists(String root_url, String relative_site_url) in D:\Users\admin\source\repos\
ExportSolution\ExportSolution\Program.cs:line 33
   at ExportSolution.Program.Main(String[] args) in D:\Users\admin\source\repos\ExportSolution\ExportSolution\Progra
m.cs:line 17

Objects SPSite , SPWeb and other with prefix "SP" exists only inside sharepoint farm. 带有前缀“ SP”的对象SPSiteSPWeb和其他对象仅存在于sharepoint服务器场内。 You must install sharepoint solution with stsadm tool. 您必须使用stsadm工具安装sharepoint解决方案。

If you want connect to sharepoint outside you must use "SharePoint SDK" with client context to web services. 如果要连接到外部的Sharepoint,则必须将“ SharePoint SDK”与客户端上下文一起使用到Web服务。 Sharepoint 2007 SDK download page Sharepoint 2007 SDK documentation Sharepoint 2007 SDK下载页面 Sharepoint 2007 SDK文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM