How do you copy a file into SharePoint using a WebService?

后端 未结 10 1508
执念已碎
执念已碎 2020-12-10 06:45

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

I want to use a WebService instead of using the ob

10条回答
  •  孤城傲影
    2020-12-10 07:17

    Here is what is currently working:

    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();
    

    So... Does anyone have an opinion as to if this "PUT" method is better in the SharePoint environment than using a built-in 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.

    Keith

提交回复
热议问题