使用visualstudio2010消费sharepoint2010web服务

本文关键字:服务 sharepoint2010web 消费 visualstudio2010 使用 | 更新日期: 2023-09-27 18:29:26

我正试图通过Visual Studio 2010使用SharePoint 2010 web服务。我想下载文档库的所有文件,这些文件只能由经过身份验证的用户访问。我发现没有任何教程有效。有人能帮我吗?

使用visualstudio2010消费sharepoint2010web服务

尝试以下代码:请尝试以下函数。你需要传递FileURL(文件的完整网址),标题(你想为下载的文件提供的传递名称。)

(注意:此功能需要为您想要下载的文档传递凭据和完整的url。我认为这对您来说已经足够了)

public string DownLoadfiletolocal(string FileURL, string Title)
{
//Copy.Copy is a webservice object that I consumed.
Copy.Copy CopyObj = new Copy.Copy();
CopyObj.Url = SiteURL + "/_vti_bin/copy.asmx"; // Dynamically passing SiteURL
NetworkCredential nc2 = new NetworkCredential();
nc2.Domain = string.Empty;
nc2.UserName = _UserName;
nc2.Password = _Password;

string copySource = FileURL; //Pass full url for document.
Copy.FieldInformation myFieldInfo = new Copy.FieldInformation();
Copy.FieldInformation[] myFieldInfoArray = { myFieldInfo };
byte[] myByteArray;
// Call the web service
uint myGetUint = CopyObj.GetItem(copySource, out myFieldInfoArray, out myByteArray);
// Convert into Base64 String
string base64String;
base64String = Convert.ToBase64String(myByteArray, 0, myByteArray.Length);
// Convert to binary array
byte[] binaryData = Convert.FromBase64String(base64String);
// Create a temporary file to write the text of the form to
string tempFileName = Path.GetTempPath() + "''" + Title;
// Write the file to temp folder
FileStream fs = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite);
fs.Write(binaryData, 0, binaryData.Length);
fs.Close();
return tempFileName;
}