使用低级 Web 服务将文档上传到 Sharepoint 库 [英] Upload Document to Sharepoint Library using low-level web services

查看:39
本文介绍了使用低级 Web 服务将文档上传到 Sharepoint 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to upload a document to a document library for Sharepoint in iOS, and having limited success.

我使用过复制.CopyIntoItems 至少让我的文档出现在目标文档库中,使用这个soap请求:

I have used Copy.CopyIntoItems to at least get my Document to appear in the target document library, using this soap request:

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

This gets me to at least have my documents appear in my library. However, the response doesn't give me any metadata about them (like GUID, etc.), which makes it harder to manage on my end. Additionally, when viewing the item in a browser, I have additional options for actions, like "View Source Item", and when deleting an extra prompt stating "This item was copied from another location...". As it is mostly the Bobs who use SharePoint, this will only serve to confuse them. Ideally, the document's actions would look the same as when uploading directly through the document library in a browser. The more transparency is better.

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

The other common solution I've seen online has been to use a combination of Lists.UpdateListItems and Lists.AddAttachment. I've gotten Lists.UpdateListItems to work properly and create a new entry (and this is nice because it gives me metadata back like GUID, and at least at first glance appears the same as a form-uploaded document). However, Lists.AddAttachment won't work for me. Using this SOAP request for the AddAttachment (The GUID is the newly added item's GUID with 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>

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

Any ideas? I'm sure I'm going down the wrong path somewhere, I'm just not sure where. Thanks!

推荐答案

今天早上开始工作了.我最终采用了最简单的方法,老实说,我没想到它会与 Microsoft API 一起使用.

Got it working this morning. I ended up doing the simplest approach, which I was honestly never expected would work with a 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 作为方法.

The key seems to be using PUT as the method.

请务必注意,不幸的是,这会遇到上述返回的元数据有限的问题,但由于该行为与直接通过 SharePoint 网站上传非常相似,因此我认为这没问题.我可能只是要重新设计我决定是否下载/更新现有文档的逻辑.

It's important to note, unfortunately, that this suffers from the problem above of limited meta-data returned, but because the behavior is so similar to uploading directly through the a SharePoint web site, I decided it was okay. I'm probably just going to rework the logic where I decide whether to download/update an existing document or not.

这篇关于使用低级 Web 服务将文档上传到 Sharepoint 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆