[英]consuming sharepoint 2010 web service with visual studio 2010
I'm trying to consume a SharePoint 2010 web service via Visual Studio 2010. I want to download all files of a document library which can only be accessed to authenticated users. 我正在尝试通过Visual Studio 2010使用SharePoint 2010 Web服务。我想下载文档库的所有文件,只能访问经过身份验证的用户。 No tutorial I found worked.
我找不到任何教程。 Can somebody help me?
有人能帮助我吗?
Try this code: Please try below function. 试试这个代码:请尝试以下功能。 you need to pass FileURL(Full web url for document), Title(Pass name you want to give for downloaded file.)
您需要传递FileURL(文档的完整网址),标题(您要为下载的文件提供通行证名称。)
(Note: this function need to pass credentials along with full url for the document you want to download. I think that would be enough for you) (注意:此功能需要传递凭据以及要下载的文档的完整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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.