如何使用 WebService 将文件复制到 SharePoint? [英] How do you copy a file into SharePoint using a WebService?

查看:19
本文介绍了如何使用 WebService 将文件复制到 SharePoint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个需要将 XML 文件放入 SharePoint 上的文档库的 winforms c# 2.0 应用程序.

I am writting a winforms c# 2.0 application that needs to put an XML file into a document library on SharePoint.

我想使用 WebService 而不是使用对象模型(此处没有可引用的 sharepoint.dll)

I want to use a WebService instead of using the object model (no sharepoint.dll to reference here)

我目前正在使用 http://webserver/site/_vti_bin/copy.asmx网络服务.

I am currently using the http://webserver/site/_vti_bin/copy.asmx webservice.

这是一些代码:

byte[] xmlByteArray;
using (MemoryStream memoryStream = new MemoryStream())
{
    xmlDocument.Save(memoryStream);
    xmlBytes = memoryStream.ToArray();
}

string[] destinationUrlArray = new string[] {"http://webserver/site/Doclib/UploadedDocument.xml"};

FieldInformation fieldInfo = new FieldInformation();
FieldInformation[] fields = { fieldInfo };


CopyResult[] resultsArray;

using (Copy copyService = new Copy())
{
    copyService.Credentials = CredentialCache.DefaultCredentials;
    copyService.Url = "http://webserver/site/_vti_bin/copy.asmx";

    copyService.Timeout = 600000;

    uint documentId = copyService.CopyIntoItems("", destinationUrlArray, fields, xmlByteArray, out resultsArray);
}

当此代码运行时,我在 resultsArray 输出参数中得到一个结果:

When this code runs, I get a single result in the resultsArray out parameter:

DestinationURL: "http://webserver/site/Doclib/UploadedDocument.xml"
ErrorCode: UnKnown
ErrorMessage: "Object reference not set to an instance of an object."  

通过我的搜索,我发现了一些可能的帮助.

From my searching, I have found a couple of possible helps.

  • 微软TechNet -- copy.asmx copyintoitems 仅在源和目标 URL 位于同一个 SPWebApplication(网站集)中时才有效."

  • Microsoft TechNet -- "The copy.asmx copyintoitems will only work if the source and destination urls are in the same SPWebApplication (Site Collection)."

微软社交 -- "未将对象引用设置为对象的实例由于 SharePoint 无法识别该特定属性而发生错误."

Microsoft Social -- "Object reference not set to an instance of an object error occurs because of SharePoint not able to identified that particular property."

这让我相信我的源 url 应该设置为某些东西,但是什么?这源自客户端工作站,没有源 URL.

This leads me to believe my source url should be set to something, but what? This is originating from a client workstation and does not have a source URL.

任何帮助都会得到应用.

Any help would be appricated.

谢谢,
基思

推荐答案

以下是目前的工作:

WebRequest request = WebRequest.Create("http://webserver/site/Doclib/UploadedDocument.xml");
request.Credentials = CredentialCache.DefaultCredentials;
request.Method = "PUT";
byte[] buffer = new byte[1024];
using (Stream stream = request.GetRequestStream())
{
    using (MemoryStream memoryStream = new MemoryStream())
    {
        dataFile.MMRXmlData.Save(memoryStream);
        memoryStream.Seek(0, SeekOrigin.Begin);
        for (int i = memoryStream.Read(buffer, 0, buffer.Length); i > 0;
            i = memoryStream.Read(buffer, 0, buffer.Length))
        {
            stream.Write(buffer, 0, i);
        }
    }
}

WebResponse response = request.GetResponse();
response.Close();

所以... 有没有人对这种PUT"方法在 SharePoint 环境中是否比使用内置 Web 服务更好有意见?

So... Does anyone have an opinion as to if this "PUT" method is better in the SharePoint environment than using a built-in webservice?

现在我不得不说PUT"方法更好,因为它可以工作并且我无法让 WebService 工作.

Right now I would have to say the "PUT" method is better since it works and I could not get the WebService to work.

基思

这篇关于如何使用 WebService 将文件复制到 SharePoint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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