使用底层Web服务将文档上传到Sharepoint Library

我正尝试将文档上传到iOS的Sharepoint文档库,并取得了有限的成功。

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

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

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

我在网上看到的其他常见解决scheme是使用Lists.UpdateListItems和Lists.AddAttachment的组合。 我已经得到了Lists.UpdateListItems正常工作,并创build一个新的条目(这是很好,因为它使我的元数据像GUID,至less乍一看似乎与表单上传的文档相同)。 但是,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> 

有任何想法吗? 我确定我在某个地方走错了路,我不知道在哪里。 谢谢!

今天早上得到了它的工作。 我最终做了最简单的方法,我真的没想到会使用微软的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网站上传的行为非常相似,所以我认为这样做是可以的。 我可能只是要重新考虑是否下载/更新现有文档的逻辑。