gpt4 book ai didi

c# - 使用 Web 服务将文档上传到共享点的最简单方法

转载 作者:行者123 更新时间:2023-11-30 15:49:00 24 4
gpt4 key购买 nike

我想上传到选定文档(从我的系统。我有它的路径)。到 Sharepoint 上的目标路径(可能是列表或文件夹)。

我正在使用网络服务 (C#) 远程访问共享点。我阅读了各种解决方案,例如使用 CopyIntoItems 方法。但是没有得到合适的例子(无法正确传递参数。尝试过 msdn 上给出的例子)

谁能帮我找到简单易懂的解决方案。

例子:

Source_FileUrl = "c:/SampleFile.txt";Desination_Url = "http://MyServer/Site/List/Folder ";

只想在 Destination_Url 上传“SampleFile.txt”。

最佳答案

试试这个

try
{

//Copy WebService Settings
string webUrl = "http://sharepointportal.ABC.com/";
WSCopy.Copy copyService = new WSCopy.Copy();
copyService.Url = webUrl + "/_vti_bin/copy.asmx";
copyService.Credentials = new NetworkCredential("username", "****", "Domain");

//Declare and initiates the Copy WebService members for uploading

string sourceUrl = "C:\\Work\\Ticket.Doc";

//Change file name if not exist then create new one
string[] destinationUrl = { "http://sharepointportal.ABC.com/personal/username/Document Upload/Testing Document/newUpload.Doc" };

WSCopy.CopyResult cResult1 = new WSCopy.CopyResult();

WSCopy.CopyResult cResult2 = new WSCopy.CopyResult();

WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

WSCopy.FieldInformation fFiledInfo = new WSCopy.FieldInformation();

fFiledInfo.DisplayName = "Description";

fFiledInfo.Type = WSCopy.FieldType.Text;

fFiledInfo.Value = "Ticket";

WSCopy.FieldInformation[] fFiledInfoArray = { fFiledInfo };

FileStream strm = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read);

byte[] fileContents = new Byte[strm.Length];

byte[] r = new Byte[strm.Length];

int ia = strm.Read(fileContents, 0, Convert.ToInt32(strm.Length));
strm.Close();
//Copy the document from Local to SharePoint

uint copyresult = copyService.CopyIntoItems(sourceUrl, destinationUrl, fFiledInfoArray, fileContents, out cResultArray);

MessageBox.Show("Suceess");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}

关于c# - 使用 Web 服务将文档上传到共享点的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2147539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com