2 回答
TA贡献1799条经验 获得超8个赞
替换下面的代码
Program.DownloadFilesFromSharePoint("http://sp.frk.com/teams/ResearchSystemsSupport/GT%20Resources/Forms/AllItems.aspx", "/TeamDocuments", @"c:\");
和
Program.DownloadFilesFromSharePoint("http://sp.frk.com/teams/ResearchSystemsSupport", "GT%20Resources/TeamDocuments", @"c:\");
站点 URL 和文件夹路径不正确。
TA贡献1797条经验 获得超4个赞
我终于想出了下面粘贴的有效代码。正如 LZ_MSFT 在评论中指出的那样,我重新检查了我正在传递的共享点链接,但他们错了,所以更改了它并且它起作用了。同样在网络凭据中,添加了域。
static void DownloadFilesFromSharePoint(string siteUrl, string siteFolderPath, string localTempLocation)
{
ClientContext ctx = new ClientContext(siteUrl);
ctx.Credentials = new NetworkCredential("username", "password", "Domain");
FileCollection files = ctx.Web.GetFolderByServerRelativeUrl(siteFolderPath).Files;
ctx.Load(files);
if (ctx.HasPendingRequest)
{
ctx.ExecuteQuery();
}
foreach (File file in files)
{
FileInformation fileInfo = File.OpenBinaryDirect(ctx, file.ServerRelativeUrl);
ctx.ExecuteQuery();
var filePath = localTempLocation + "\\" + file.Name;
System.IO.FileStream fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
fileInfo.Stream.CopyTo(fileStream);
}
}
调用函数:
static void Main(string[] args)
{
Program.DownloadFilesFromSharePoint(@"http://sp.frk.com/teams/ResearchSystemsSupport", @"http://sp.frk.com/teams/ResearchSystemsSupport/Global%20Equity%20Group/Daily_Checks", @"C:\Temp");
}
- 2 回答
- 0 关注
- 826 浏览
添加回答
举报