別人共享一個sharepoint的檔案夾給我,我希望通過c#代碼操作這個檔案夾,例如:新建子目錄,上傳檔案等
但是不清楚該怎么連接這個檔案夾,地址類似這種:
https://zfhk.sharepoint.com/:f:/s/JIM-ExCom2/EhFbuaoeYWJLk8NH4NvKGl4BuTFGNRuaR1BnOQitYSqOEA?email=xxxx%40xxxxuuuu.com&e=dZvO6E
uj5u.com熱心網友回復:
你試試把這個檔案夾用onedrive for business同步到本地,然后進行操作,網路暢通的話應該會自動同步uj5u.com熱心網友回復:
static void Main(string[] args){
string SiteUrl = "https://You.sharepoint.com/sites/Upload";
string DocumentLibrary = "UploadLibrary";
string FileName = @"C:\testupload.pdf";
string CustomerFolder = "1564_dsfgsst";
string UserName = "samir.daoudi@******.co.uk";
string Password = "*****";
UploadFileToSharePoint(SiteUrl, DocumentLibrary, CustomerFolder, FileName, UserName, Password);
}
uj5u.com熱心網友回復:
private static void UploadFileToSharePoint(string SiteUrl, string DocLibrary, string ClientSubFolder, string FileName, string Login, string Password){
try
{
#region ConnectToSharePoint
var securePassword = new SecureString();
foreach (char c in Password)
{ securePassword.AppendChar(c); }
var onlineCredentials = new SP.SharePointOnlineCredentials(Login, securePassword);
#endregion
#region Insert the data
using (SP.ClientContext CContext = new SP.ClientContext(SiteUrl))
{
CContext.Credentials = onlineCredentials;
SP.Web web = CContext.Web;
SP.FileCreationInformation newFile = new SP.FileCreationInformation();
byte[] FileContent = System.IO.File.ReadAllBytes(FileName);
newFile.ContentStream = new MemoryStream(FileContent);
newFile.Url = Path.GetFileName(FileName);
SP.List DocumentLibrary = web.Lists.GetByTitle(DocLibrary);
//SP.Folder folder = DocumentLibrary.RootFolder.Folders.GetByUrl(ClientSubFolder);
SP.Folder Clientfolder = DocumentLibrary.RootFolder.Folders.Add(ClientSubFolder);
Clientfolder.Update();
SP.File uploadFile = Clientfolder.Files.Add(newFile);
CContext.Load(DocumentLibrary);
CContext.Load(uploadFile);
CContext.ExecuteQuery();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("The File has been uploaded"+Environment.NewLine+"FileUrl -->"+SiteUrl+"/"+DocLibrary+"/"+ClientSubFolder+"/" +Path.GetFileName(FileName));
}
#endregion
}
catch (Exception exp)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(exp.Message + Environment.NewLine + exp.StackTrace);
}
finally
{
Console.ReadLine();
}
}
uj5u.com熱心網友回復:
可以使用 COMS API 操作,樓上的Code應該就可以轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/7180.html
標籤:SharePoint
上一篇:企業資訊化,如何做?!
