如何从sharepoint网址下载文件 [英] how to download files from sharepoint url
问题描述
早安朋友。
我想从共享点下载文件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.
推荐答案
如果您知道文档库名称,则可以执行此操作。我有时会这样做。希望代码仍然有用:)如果不是这样尝试。
If you know the document library name, you can do it. I did this sometimes back. Hope the code still works :) If not just try along these lines.
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);
}
}
}
文件/ dll位于任何SharePoint 2013服务器上%ProgramFiles%\ Common Files \Microsoft Shared\web服务器扩展\\\ _APAPI或在任何Sharepoint 2010服务器上%ProgramFiles%\ Common Files \ MicroSoftoft\web服务器扩展\\\\\\\\\\\您可以从服务器复制dll,也可以从 http:// www下载它们。 .microsoft.com / zh-CN / download / details.aspx?id = 35585 [ ^ ]
关于CopyStream:你真的不需要使用它,除非您使用的是.NET3.5或之前的版本。因为.NET3.5没有任何内置方法来复制流;所以我不得不使用一种方法来手动复制。正如我在上一篇回复中提到的那样;这是一段旧代码。但是.NET 4.0有
The files/dlls are located on any SharePoint 2013 server at %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\15\ISAPI or on any Sharepoint 2010 server at %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI. You can copy the dlls from the servers or else you can download them from http://www.microsoft.com/en-us/download/details.aspx?id=35585[^]
Regarding the CopyStream: You don't really need to use that unless you are using .NET3.5 or before. Because .NET3.5 didn't have any in-built method to copy the stream; so I had to use a method to manually copy. As I mentioned in my previous reply; It was an old piece of code. But .NET 4.0 has
Stream.CopyTo
而.NET 4.5有
Stream.CopyToAsync
所以你可以使用其中任何一个将流复制到另一个。
So you can use either one of them to copy the stream to another.
这篇关于如何从sharepoint网址下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!