2012-04-09 76 views
2

我正尝试将文档上传到iOS的Sharepoint文档库,并且成功有限。使用低级Web服务将文档上传到Sharepoint库

我已经使用Copy.CopyIntoItems至少让我的文档出现在目标文档库,使用这个SOAP请求:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
     <SourceUrl>[server url]</SourceUrl> 
     <DestinationUrls><string>[server url]</string></DestinationUrls> 
     <Fields></Fields> 
     <Stream>[base 64 encoded string]</Stream> 
    </CopyIntoItems> 
    </soap:Body> 
</soap:Envelope> 

这让我至少有我的文档出现在我的图书馆。但是,响应没有给我任何有关它们的元数据(比如GUID等),这使得我很难管理。此外,在浏览器中查看项目时,我还有其他操作选项,例如“查看源项目”,以及在删除额外提示时指出“此项目已从其他位置复制...”。由于它主要是使用SharePoint的Bob,这只会使它们感到困惑。理想情况下,文档的操作看起来与直接通过浏览器中的文档库上传时相同。透明度越高越好。

我在网上看到的其他常见解决方案是使用Lists.UpdateListItems和Lists.AddAttachment的组合。我已经得到Lists.UpdateListItems正常工作并创建一个新条目(这很好,因为它使我的元数据像GUID一样,至少乍一看出现与表单上传文档相同)。但是,Lists.AddAttachment不适用于我。使用此SOAP请求的AddAttachment(GUID是新添加的项目的GUID与UpdateListItems):

<?xml version="1.0" ?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soap:Body> 
    <AddAttachment xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
     <listName>Test</listName> 
     <listItemID>{1F214D95-B92B-4E10-8B96-4B04DC6DA9B6}</listItemID> 
     <fileName>screenshot.png</fileName> 
     <attachment>[base 64 string]</attachment> 
    </AddAttachment> 
    </soap:Body> 
</soap:Envelope> 

我得到如下回应:

<?xml version="1.0" ?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soap:Body> 
    <soap:Fault> 
     <faultcode> 
     soap:Server 
     </faultcode> 
     <faultstring> 
     Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown. 
     </faultstring> 
     <detail> 
     <errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
      Input string was not in a correct format. 
     </errorstring> 
     </detail> 
    </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

任何想法?我确信我会在某个地方走错路,我只是不确定在哪里。谢谢!

+0

下一次尝试,对于listItemId,而不是使用来自updateListItems(这是一个GUID)的ows_UniqueId,我将它设置为使用ows_ID(这只是一个简单的数字,在本例中为44)。这一次,我的回应是看似更常见的“价值不在预期范围内”。 Soooo ...仍然没有工作,但我认为这更接近? – cscott530 2012-04-09 17:35:36

回答

1

今天早上明白了。我最终做了最简单的方法,我真的没有想到会使用Microsoft API。

NSString *fullPath = @"https://site/library/folders/document.txt"; 
NSURL *url = [NSURL URLWithString: fullPath]; 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
request.HTTPMethod = @"PUT"; 
request.HTTPBody = [NSData {documentData}]; 

//this is the authentication Cookie acquired in a previous request. 
[request addValue:cookie forHTTPHeaderField:@"Cookie"]; 
[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 

关键似乎是使用PUT作为方法。

不幸的是,不幸的是,这个问题遭受了上述有限元数据返回的问题,但由于行为与通过SharePoint网站直接上传的行为非常相似,所以我认为它没问题。我可能只是要重新考虑是否下载/更新现有文档的逻辑。

相关问题