第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用C#將excel文件從sharepoint站點(diǎn)下載到本地系統(tǒng)

使用C#將excel文件從sharepoint站點(diǎn)下載到本地系統(tǒng)

C#
慕慕森 2021-11-28 16:40:24
我需要從 sharepoint 下載一個(gè) excel 文件到我的本地系統(tǒng)。我寫了下面的方法。    internal static void DownloadFilesFromSharePoint(string siteUrl, string folderPath, string tempLocation)    {        ClientContext ctx = new ClientContext(siteUrl);        ctx.Credentials = new NetworkCredential("username", "password");        FileCollection files = ctx.Web.GetFolderByServerRelativeUrl(folderPath).Files;        ctx.Load(files);        ctx.ExecuteQuery();----FAILED HERE        foreach (File file in files)        {            FileInformation fileInfo = File.OpenBinaryDirect(ctx, file.ServerRelativeUrl);            ctx.ExecuteQuery();            var filePath = tempLocation + file.Name;            using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))            {                fileInfo.Stream.CopyTo(fileStream);            }        }    }要調(diào)用上述方法,我在 Main 方法中有以下內(nèi)容:    public static void Main()    {    Program.DownloadFilesFromSharePoint("http://sp.frk.com/teams/ResearchSystemsSupport/GT%20Resources/Forms/AllItems.aspx", "/TeamDocuments", @"c:\");    }但是上面的代碼不起作用。我在調(diào)試時(shí)標(biāo)記了代碼給出異常的點(diǎn)(通過(guò)標(biāo)記----FAILED HERE)。任何人都可以在這里指出問(wèn)題。任何人都可以幫助我。如果可以,請(qǐng)給我一個(gè)詳細(xì)的解釋。
查看完整描述

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 和文件夾路徑不正確。


查看完整回答
反對(duì) 回復(fù) 2021-11-28
?
繁星coding

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");       

    }


查看完整回答
反對(duì) 回復(fù) 2021-11-28
  • 2 回答
  • 0 關(guān)注
  • 888 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)