通过内置 Web 服务将文件上传到 SharePoint

发布于 2024-07-05 04:09:37 字数 445 浏览 5 评论 0原文

通过 WSS 3.0 版本公开的内置 Web 服务将文件上传到 SharePoint 服务器上的文档库的最佳方法是什么?

遵循两个初始答案...

  • 我们肯定需要使用 Web 服务层,因为我们将从远程客户端应用程序进行这些调用。

  • WebDAV 方法适合我们,但我们希望与 Web 服务集成方法保持一致。

另外还有一个用于上传文件的网络服务,虽然很痛苦,但一直有效。

您指的是“复印”服务吗? 我们已成功使用此服务的 CopyIntoItems 方法。 这是否是仅使用 WSS Web 服务 API 将文件上传到文档库的推荐方法?

我已将我们的代码作为建议的答案发布。

What is the best way to upload a file to a Document Library on a SharePoint server through the built-in web services that version WSS 3.0 exposes?

Following the two initial answers...

  • We definitely need to use the Web Service layer as we will be making these calls from remote client applications.

  • The WebDAV method would work for us, but we would prefer to be consistent with the web service integration method.

There is additionally a web service to upload files, painful but works all the time.

Are you referring to the “Copy” service?
We have been successful with this service’s CopyIntoItems method. Would this be the recommended way to upload a file to Document Libraries using only the WSS web service API?

I have posted our code as a suggested answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

无名指的心愿 2024-07-12 04:09:37

使用 WSS“复制”Web 服务将文档上传到图书馆的示例...

public static void UploadFile2007(string destinationUrl, byte[] fileData)
{
    // List of desination Urls, Just one in this example.
    string[] destinationUrls = { Uri.EscapeUriString(destinationUrl) };

    // Empty Field Information. This can be populated but not for this example.
    SharePoint2007CopyService.FieldInformation information = new 
        SharePoint2007CopyService.FieldInformation();
    SharePoint2007CopyService.FieldInformation[] info = { information };

    // To receive the result Xml.
    SharePoint2007CopyService.CopyResult[] result;

    // Create the Copy web service instance configured from the web.config file.
    SharePoint2007CopyService.CopySoapClient
    CopyService2007 = new CopySoapClient("CopySoap");
    CopyService2007.ClientCredentials.Windows.ClientCredential = 
        CredentialCache.DefaultNetworkCredentials;
    CopyService2007.ClientCredentials.Windows.AllowedImpersonationLevel = 
        System.Security.Principal.TokenImpersonationLevel.Delegation;

    CopyService2007.CopyIntoItems(destinationUrl, destinationUrls, info, fileData, out result);

    if (result[0].ErrorCode != SharePoint2007CopyService.CopyErrorCode.Success)
    {
        // ...
    }
}

Example of using the WSS "Copy" Web service to upload a document to a library...

public static void UploadFile2007(string destinationUrl, byte[] fileData)
{
    // List of desination Urls, Just one in this example.
    string[] destinationUrls = { Uri.EscapeUriString(destinationUrl) };

    // Empty Field Information. This can be populated but not for this example.
    SharePoint2007CopyService.FieldInformation information = new 
        SharePoint2007CopyService.FieldInformation();
    SharePoint2007CopyService.FieldInformation[] info = { information };

    // To receive the result Xml.
    SharePoint2007CopyService.CopyResult[] result;

    // Create the Copy web service instance configured from the web.config file.
    SharePoint2007CopyService.CopySoapClient
    CopyService2007 = new CopySoapClient("CopySoap");
    CopyService2007.ClientCredentials.Windows.ClientCredential = 
        CredentialCache.DefaultNetworkCredentials;
    CopyService2007.ClientCredentials.Windows.AllowedImpersonationLevel = 
        System.Security.Principal.TokenImpersonationLevel.Delegation;

    CopyService2007.CopyIntoItems(destinationUrl, destinationUrls, info, fileData, out result);

    if (result[0].ErrorCode != SharePoint2007CopyService.CopyErrorCode.Success)
    {
        // ...
    }
}
情栀口红 2024-07-12 04:09:37

来自工作中的大学:

懒惰方式:您的 Windows WebDAV 文件系统接口。 作为一种编程解决方案,它很糟糕,因为它依赖于操作系统上运行的 WindowsClient 服务,并且仅适用于在端口 80 上运行的网站。将驱动器映射到文档库并进行文件复制。

还有一个用于上传文件的网络服务,虽然很痛苦,但一直有效。

我相信您可以通过 FrontPage API 上传文件,但我不知道有谁真正使用它。

From a colleage at work:

Lazy way: your Windows WebDAV filesystem interface. It is bad as a programmatic solution because it relies on the WindowsClient service running on your OS, and also only works on websites running on port 80. Map a drive to the document library and get with the file copying.

There is additionally a web service to upload files, painful but works all the time.

I believe you are able to upload files via the FrontPage API but I don’t know of anyone who actually uses it.

梦途 2024-07-12 04:09:37

不确定到底要使用哪个 Web 服务,但如果您可以使用 SharePoint .NET API Dll,那么使用 SPList 和 SPLibrary.Items.Add 就非常简单。

Not sure on exactly which web service to use, but if you are in a position where you can use the SharePoint .NET API Dlls, then using the SPList and SPLibrary.Items.Add is really easy.

眼睛会笑 2024-07-12 04:09:37

我很幸运地使用了此处描述的 DocLibHelper 包装类: http://geek.hubkey.com/2007/10/upload-file-to-sharepoint-document.html

I've had good luck using the DocLibHelper wrapper class described here: http://geek.hubkey.com/2007/10/upload-file-to-sharepoint-document.html

掐死时间 2024-07-12 04:09:37
public static void UploadFile(byte[] fileData) {
  var copy = new Copy {
    Url = "http://servername/sitename/_vti_bin/copy.asmx", 
    UseDefaultCredentials = true
  };

  string destinationUrl = "http://servername/sitename/doclibrary/filename";
  string[] destinationUrls = {destinationUrl};

  var info1 = new FieldInformation
                {
                  DisplayName = "Title", 
                  InternalName = "Title", 
                  Type = FieldType.Text, 
                  Value = "New Title"
                };

  FieldInformation[] info = {info1};
  var copyResult = new CopyResult();
  CopyResult[] copyResults = {copyResult};

  copy.CopyIntoItems(
    destinationUrl, destinationUrls, info, fileData, out copyResults);
}

注意:CopyIntoItems 的第一个参数更改为文件名 Path.GetFileName(destinationUrl) 会使取消链接消息消失。

public static void UploadFile(byte[] fileData) {
  var copy = new Copy {
    Url = "http://servername/sitename/_vti_bin/copy.asmx", 
    UseDefaultCredentials = true
  };

  string destinationUrl = "http://servername/sitename/doclibrary/filename";
  string[] destinationUrls = {destinationUrl};

  var info1 = new FieldInformation
                {
                  DisplayName = "Title", 
                  InternalName = "Title", 
                  Type = FieldType.Text, 
                  Value = "New Title"
                };

  FieldInformation[] info = {info1};
  var copyResult = new CopyResult();
  CopyResult[] copyResults = {copyResult};

  copy.CopyIntoItems(
    destinationUrl, destinationUrls, info, fileData, out copyResults);
}

NOTE: Changing the 1st parameter of CopyIntoItems to the file name, Path.GetFileName(destinationUrl), makes the unlink message disappear.

君勿笑 2024-07-12 04:09:37

另一种选择是使用普通的 HTTP PUT:

WebClient webclient = new WebClient();
webclient.Credentials = new NetworkCredential(_userName, _password, _domain);
webclient.UploadFile(remoteFileURL, "PUT", FilePath);
webclient.Dispose();

其中 RemoteFileURL 指向您的 SharePoint 文档库...

Another option is to use plain ol' HTTP PUT:

WebClient webclient = new WebClient();
webclient.Credentials = new NetworkCredential(_userName, _password, _domain);
webclient.UploadFile(remoteFileURL, "PUT", FilePath);
webclient.Dispose();

Where remoteFileURL points to your SharePoint document library...

地狱即天堂 2024-07-12 04:09:37

有几件事需要考虑:

  • Copy.CopyIntoItems 需要文档已存在于某个服务器。 该文档作为 Web 服务调用的参数传递,这将限制文档的大小。 (请参阅http:// Social.msdn.microsoft.com/Forums/en-AU/sharepointdevelopment/thread/e4e00092-b312-4d4c-a0d2-1cfc2beb9a6c
  • “http put”方法(即 webdav ...)只会放置文档在库中,但不设置字段值
  • 后调用 Lists.UpdateListItem
  • 来更新字段值,您可以在“http put”文档库可以有目录
  • ,您可以使用“http mkcol”创建它们,您可能想用列表签入文件。 CheckInFile
  • 您还可以创建使用 SPxxx .Net API 的自定义 Web 服务,但必须在服务器上安装该新 Web 服务。 它可以节省前往服务器的次数。

There are a couple of things to consider:

  • Copy.CopyIntoItems needs the document to be already present at some server. The document is passed as a parameter of the webservice call, which will limit how large the document can be. (See http://social.msdn.microsoft.com/Forums/en-AU/sharepointdevelopment/thread/e4e00092-b312-4d4c-a0d2-1cfc2beb9a6c)
  • the 'http put' method (ie webdav...) will only put the document in the library, but not set field values
  • to update field values you can call Lists.UpdateListItem after the 'http put'
  • document libraries can have directories, you can make them with 'http mkcol'
  • you may want to check in files with Lists.CheckInFile
  • you can also create a custom webservice that uses the SPxxx .Net API, but that new webservice will have to be installed on the server. It could save trips to the server.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文