2 回答

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊
只需修改代碼片段如下:
using Microsoft.SharePoint.Client;
using System.IO;
using System.Linq;
using System.Security;
namespace CSOM
{
class Program
{
static void Main(string[] args)
{
using (ClientContext ctx = new ClientContext("https://tenant.sharepoint.com/sites/dev"))
{
string password = "*****";
string account = "user@tenant.onmicrosoft.com";
var secret = new SecureString();
foreach (char c in password)
{
secret.AppendChar(c);
}
ctx.Credentials = new SharePointOnlineCredentials(account, secret);
List mylibrary = ctx.Web.Lists.GetByTitle("Documents");
FileCollection files = mylibrary.RootFolder.Folders.GetByUrl("/sites/dev/shared documents/folder1").Files;
ctx.Load(files);
ctx.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.File file in files)
{
FileInformation fileinfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, file.ServerRelativeUrl);
ctx.ExecuteQuery();
using (FileStream filestream = new FileStream("D:" + "\\" + file.Name, FileMode.Create))
{
fileinfo.Stream.CopyTo(filestream);
}
}
files.ToList().ForEach(file => file.DeleteObject());
ctx.ExecuteQuery();
};
}
}
}
添加最后兩行以在下載后從文件夾中刪除文件,我已經(jīng)測(cè)試過并且它在我這邊工作。
- 2 回答
- 0 關(guān)注
- 178 瀏覽
添加回答
舉報(bào)