简体   繁体   English

如何在C#Word加载项中打开SharePoint 2010文档

[英]How to open SharePoint 2010 document in C# Word add-in

I'm developing an MS Word 2010 add-in (using C#), which has a custom Ribbon tab. 我正在开发MS Word 2010加载项(使用C#),该加载项具有自定义的功能区选项卡。 In that tab there is a button, which should open a particular Word document (MyTemplate.docx), which is located in SharePoint 2010 server's Shared Documents library. 在该选项卡中,有一个按钮,应该打开一个特定的Word文档(MyTemplate.docx),该文档位于SharePoint 2010服务器的“共享文档”库中。 The URL of my development server (internal) is 'http://sharepoint2010'. 我的开发服务器的URL(内部)是“ http:// sharepoint2010”。 I'm trying to use SP object model elements, such as SPSite, SPWeb, etc... When I try : 我正在尝试使用SP对象模型元素,例如SPSite,SPWeb等。

SPSite site = new SPSite(@"http://sharepoint2010");

I get error: " The Web application at 'http://sharepoint2010' could not be found " 我收到错误消息:“ 找不到位于'http:// sharepoint2010'的Web应用程序

I do have a valid Web Service Reference: 我有一个有效的Web服务参考:

HomeDataContext dc = new HomeDataContext(new Uri("http://sharepoint2010/_vti_bin/listdata.svc"));

which allows me to obtain a listing of documents in the Shared Documents library. 这样我就可以在“共享文档”库中获取文档列表。 I'm able to iterate through that list and obtain individual SharedDocumentItem, but I don't understand how to open it as a Word document. 我可以遍历该列表并获得单个SharedDocumentItem,但是我不知道如何将其作为Word文档打开。

You cannot use SharePoint object model in a remote-access scenario. 您不能在远程访问方案中使用SharePoint对象模型。 The object model (mostly represented by Microsoft.SharePoint.dll ) depends on the server code, so it can be used on the SharePoint server only . 对象模型(主要由Microsoft.SharePoint.dll表示)取决于服务器代码,因此只能在SharePoint服务器上使用 That's why instantiating SPSite will always throw an exception. 这就是为什么实例化SPSite 总是会引发异常的原因。

Also note that the URL passed to SPSite has nothing to do with accessing a site via HTTP, web services or whatever. 还要注意,传递给SPSite的URL与通过HTTP,Web服务或其他任何方式访问站点无关。 It's interpreted as the server-side locator of the site collection. 它被解释为网站集的服务器端定位器。

Should you really need it client-side, have a look client object model . 如果您确实需要客户端,请查看客户端对象模型

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

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