Upload a file to SharePoint through the built-in web services

后端 未结 7 879
悲&欢浪女
悲&欢浪女 2020-11-27 03:37

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

7条回答
  •  抹茶落季
    2020-11-27 04:19

    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.

提交回复
热议问题