2015-05-14 68 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/