代码之家  ›  专栏  ›  技术社区  ›  Andy McCluggage hunter

通过内置web服务将文件上载到SharePoint

  •  31
  • Andy McCluggage hunter  · 技术社区  · 17 年前

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

    下面是两个初步答案。。。

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

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

    CopyIntoItems 方法这是仅使用WSS web服务API将文件上载到文档库的推荐方法吗?

    7 回复  |  直到 17 年前
        1
  •  17
  •   Ocelot20    12 年前

    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)
        {
            // ...
        }
    }
    
        2
  •  9
  •   Jim Harte    17 年前

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

        3
  •  8
  •   ErikE    15 年前

        4
  •  6
  •   Luke Hutton    13 年前
    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)

        6
  •  1
  •   Community Mohan Dere    6 年前

    来自工作中的同事:

    惰性方式:您的Windows WebDAV文件系统接口。作为一个编程解决方案,它是不好的,因为它依赖于在操作系统上运行的WindowsClient服务,并且只在端口80上运行的网站上工作。将驱动器映射到文档库并开始文件复制。

        7
  •  1
  •   Daniel O    17 年前

    不确定要使用哪种web服务,但如果您可以使用SharePoint.NET API DLL,那么使用SPList和SPLibrary.Items.Add就非常容易了。