使用低级Web服务将文档上载到Sharepoint Library

时间:2012-04-09 17:01:25

标签: ios sharepoint soap

我正在尝试将文档上传到iOS中的Sharepoint文档库,但成效有限。

我使用Copy.CopyIntoItems至少使用此肥皂请求将我的文档显示在目标文档库中:

<?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的Bobs,这只会让他们感到困惑。理想情况下,文档的操作与在浏览器中直接通过文档库上载时的操作相同。透明度越高越好。

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

<?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>

有什么想法吗?我确定我在某个地方走错路,我只是不确定在哪里。谢谢!

1 个答案:

答案 0 :(得分: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网站上传相似,我认为没关系。我可能只是重新编写逻辑,决定是否下载/更新现有文档。