问题描述
早安朋友。
我想从共享点下载文件URL。但我无法下载。
i找到了代码,但所有代码只下载了一个文件。
但我想下载SharePoint门户网站链接中的所有文件。 />
在该链接上我有一个列,例如,
文件名已发布日期
这里可能会发布10到15个文件我想在运行程序时下载我本地文件夹中的所有文件。
并且名称格式将相同,只有日期可以在发布日期列中更改。
i想要循环浏览所有文件,以便我们可以逐个下载所有文件。
请帮我急。
先谢谢。
Hi,
Good Morning Friends.
I am trying to download files from share point URL. but i am unable to download.
i found code but all code for downloading only one file.
but i want to download all the files present in SharePoint portal link.
on that link i have an column like,
File Name posted Date
Here may be 10 to 15 file can be posted i want to download all files in my local folder when i run the program.
And names format will be same only dates can change in posted date column.
i want to do looping through all files so we can download all the files one by one.
Please help me its urgent.
Thanks In advance.
推荐答案
using SPC = Microsoft.SharePoint.Client;
using (SPC.ClientContext context = new SPC.ClientContext(siteUrl))
{
context.Credentials = new NetworkCredential("username", "password");
SPC.Web myWeb = context.Web;
context.Load(myWeb, website => website.Title);
context.ExecuteQuery();
//Load Sample Documents document library
SPC.List documentsList = myWeb.Lists.GetByTitle("Sample Documents");
context.Load(documentsList);
context.ExecuteQuery();
//Load documents in the document library
SPC.ListItemCollection listItemCollection = documentsList.GetItems(new SPC.CamlQuery());
context.Load(listItemCollection);
context.ExecuteQuery();
foreach (SPC.ListItem item in listItemCollection)
{
SPC.FileInformation fileInfo = SPC.File.OpenBinaryDirect(context, item["FileRef"].ToString());
using (MemoryStream memoryStream = new MemoryStream())
{
CopyStream(fileInfo.Stream, memoryStream);
//Retrieved file is saved as byte array
Byte[] retrievedFile= memoryStream.ToArray();
string outFileName = @"C:\temp\test\" + item["FileLeafRef"].ToString();
//Write the file to disk
File.WriteAllBytes(outFileName, retrievedFile);
}
}
}
Stream.CopyTo
而.NET 4.5有
Stream.CopyToAsync
所以你可以使用其中任何一个将流复制到另一个。
So you can use either one of them to copy the stream to another.
这篇关于如何从sharepoint网址下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!