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

后端 未结 7 892
悲&欢浪女
悲&欢浪女 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:40

    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)
        {
            // ...
        }
    }
    

提交回复
热议问题