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

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

如何使用 CSOM 將(多個(gè))文件上傳到 SharePoint Online?

如何使用 CSOM 將(多個(gè))文件上傳到 SharePoint Online?

C#
繁華開滿天機(jī) 2022-12-04 13:09:14
我有一個(gè) Web 表單,可以將一些輸入的數(shù)據(jù)作為一個(gè)新的列表項(xiàng)上傳到 SharePoint 列表,效果很好。我試圖添加一個(gè)新代碼來(lái)通過兩個(gè)單獨(dú)的<asp:FileUpload>控件上傳兩個(gè)文件。以下代碼protected void sendToSharePoint() {}無(wú)法將任何一個(gè)文件上傳到指定的 SharePoint 文檔庫(kù),更不用說(shuō)兩者了:默認(rèn).aspx://Existing code<asp:FileUpload ID="upldGradeReport" runat="server" /><asp:FileUpload ID="upldExpenseReceipt" runat="server" /><asp:Button ID="btnSubmitForm" OnClick="SubmitButton_Click" runat="server" Text="Submit" />默認(rèn).aspx.cs:using System;using System.DirectoryServices;using System.IO;using System.Security;using System.Web.UI;using Microsoft.SharePoint.Client;using ClientOM = Microsoft.SharePoint.Client;//I left out the NameSpace and default public partial class wrapper, but they're here.public ClientContext SPClientContext { get; set; }public string SPErrorMsg { get; set; }protected void SubmitButton_Click(object sender, EventArgs e) {    sendToSharePoint();    Response.BufferOutput = true;    Response.Redirect("Submission.aspx");}protected void sendToSharePoint() {    try {        string siteUrl = "<sharepoint site url>";        ClientContext clientContext = new ClientContext(siteUrl);        clientContext.Credentials = new SharePointOnlineCredentials("<my username>", "<my password>");        string sDocName = string.Empty;        string sDocName1 = string.Empty;        Uri uri = new Uri(siteUrl);        string sSPSiteRelativeURL = uri.AbsolutePath;        sDocName = UploadFile(upldGradeReport.FileContent, upldGradeReport.FileName, sSPSiteRelativeURL, "<sharepoint document library>");        sDocName1 = UploadFile(upldExpenseReceipt.FileContent, upldExpenseReceipt.FileName, sSPSiteRelativeURL, "<sharepoint document library>");        //prior CSOM code to insert values into a new List Item exists here        clientContext.ExecuteQuery();    } catch (Exception ex) {        String ThisError = ex.Message;    }}創(chuàng)建新 ListItem 并將表單的其余輸入數(shù)據(jù)上傳到單獨(dú)的 SharePoint 列表的代碼在提交時(shí)仍然有效,我已經(jīng)確認(rèn)憑據(jù)正確并且正在使用的帳戶有權(quán)將文件上傳到文檔圖書館。我究竟做錯(cuò)了什么?
查看完整描述

1 回答

?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊

我在本地環(huán)境中測(cè)試了以下代碼;它工作正常。


<div>

    <asp:FileUpload ID="upldGradeReport" runat="server" />

    <asp:FileUpload ID="upldExpenseReceipt" runat="server" />


    <asp:Button ID="btnSubmitForm" OnClick="SubmitButton_Click" runat="server" Text="Submit" />

</div>



protected void SubmitButton_Click(object sender, EventArgs e)

{

    sendToSharePoint();

    Response.BufferOutput = true;

    Response.Redirect("Submission.aspx");

}


protected void sendToSharePoint()

{


    try

    {

        string siteUrl = "https://tenant.sharepoint.com/sites/lee";


        ClientContext clientContext = new ClientContext(siteUrl);

        SecureString securePassword = new SecureString();

        foreach (char c in "password".ToCharArray()) securePassword.AppendChar(c);

        clientContext.Credentials = new SharePointOnlineCredentials("lee@tenant.onmicrosoft.com", securePassword);                

        string sDocName = string.Empty;

        string sDocName1 = string.Empty;

        Uri uri = new Uri(siteUrl);

        string sSPSiteRelativeURL = uri.AbsolutePath;

        sDocName = UploadFile(clientContext,upldGradeReport.FileContent, upldGradeReport.FileName, sSPSiteRelativeURL, "MyDoc");

        sDocName1 = UploadFile(clientContext,upldExpenseReceipt.FileContent, upldExpenseReceipt.FileName, sSPSiteRelativeURL, "MyDoc");


        //prior CSOM code to insert values into a new List Item exists here


        //clientContext.ExecuteQuery();

    }

    catch (Exception ex)

    {

        String ThisError = ex.Message;

    }

}


public String UploadFile(ClientContext clientContext,Stream fs, string sFileName, string sSPSiteRelativeURL, string sLibraryName)

{

    string sDocName = string.Empty;

    try

    {

        var sFileURL = String.Format("{0}/{1}/{2}", sSPSiteRelativeURL, sLibraryName, sFileName);


        Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, sFileURL, fs, true);

        sDocName = sFileName;

    }

    catch (Exception ex)

    {

        sDocName = string.Empty;

        //SPErrorMsg = ex.Message;

    }

    return sDocName;

}



查看完整回答
反對(duì) 回復(fù) 2022-12-04
  • 1 回答
  • 0 關(guān)注
  • 144 瀏覽

添加回答

舉報(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)