2015-05-14 73 views
0

我正嘗試使用SharePoint的CopyService上傳文件。它工作正常,直到我意識到當文件名以'。'結尾時。 (點)例如測試。 .docx,test ... docx,test .... docx等。我將CopyResult作爲無效的URL。使用CopyService上傳文件錯誤SharePoint

我不是100%確定如果這些名稱是有效的,應該像簡單的文件名稱上傳,或者我應該顯示錯誤消息說我的用戶無效的文件名。

請幫忙。

我的代碼 -

public static void CopyImageOnServer(string sourceUrl, string destinationUrl, byte[] fileData) 
    { 
     PBSWebApplication.CopyServiceReference.CopySoapClient proxy = Utility.GetServerCopyProxy(); 

     // 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; 

     // Empty Field Information. This can be populated but not for this example. 
     CopyServiceReference.FieldInformation information = new CopyServiceReference.FieldInformation(); 

     CopyServiceReference.FieldInformation[] info = { information }; 

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

     uint returnValue = proxy.CopyIntoItems(sourceUrl, destinationUrls, info, fileData, out result); 

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

感謝。

回答

0

如果您不需要使用SOAP服務,我會強烈建議使用CSOM或REST來完成您的任務。 CopyService很難處理,而REST現在被認爲是標準。我曾經有過一個您正在嘗試做的工作示例,但我將其轉換爲CSOM,其中有許多TechNet上提供的簡單示例。如果你想避免使用不隨.NET分發的附加庫,那麼使用REST。

下面是一個使用REST在C#上傳文件的例子:

    string url = "http://your.sharepoint.site"; 
        client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }); 
        client.BaseAddress = new System.Uri(url); 
        client.DefaultRequestHeaders.Clear(); 
        client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose"); 
        client.DefaultRequestHeaders.Add("X-RequestDigest", digest); 
        client.DefaultRequestHeaders.Add("X-HTTP-Method", "POST"); 
        client.DefaultRequestHeaders.Add("binaryStringRequestBody", "true"); 

        ByteArrayContent file = new ByteArrayContent(fileBytes); 
        HttpResponseMessage response = await client.PostAsync(String.Concat("_api/web/lists/getByTitle('Images')/RootFolder/Files/add(url='", filename, ".jpg',overwrite='true')?$expand=ListItemAllFields"), file); 
        response.EnsureSuccessStatusCode(); 

        if (response.IsSuccessStatusCode) 
        {} 

我已經得到消化,在這裏更新元數據的例子,如果你需要更多的例子:

https://arcandotnet.wordpress.com/2015/04/01/sharepoint-2013-rest-services-using-c-and-the-httpclient-for-windows-store-apps/