2 回答

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
替換下面的代碼
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:\");
站點(diǎn) URL 和文件夾路徑不正確。

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊
我終于想出了下面粘貼的有效代碼。正如 LZ_MSFT 在評(píng)論中指出的那樣,我重新檢查了我正在傳遞的共享點(diǎn)鏈接,但他們錯(cuò)了,所以更改了它并且它起作用了。同樣在網(wǎng)絡(luò)憑據(jù)中,添加了域。
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);
}
}
調(diào)用函數(shù):
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 關(guān)注
- 888 瀏覽
添加回答
舉報(bào)