zoukankan      html  css  js  c++  java
  • SharePoint Client Add Folder,file to Library

    public void UploadDocument(string siteURL, string documentListName,
    string documentListURL, string documentName,
    
    byte[] documentStream)
    {
    
    using (ClientContext clientContext = new ClientContext(siteURL))
    {        
    
    //Get Document List
    List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);
    
    var fileCreationInformation = new FileCreationInformation();
    //Assign to content byte[] i.e. documentStream
    
    fileCreationInformation.Content = documentStream;
    //Allow owerwrite of document
    
    fileCreationInformation.Overwrite = true;
    //Upload URL
    
    fileCreationInformation.Url = siteURL + documentListURL + documentName;
    Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
        fileCreationInformation);
    
    //Update the metadata for a field having name "DocType"
    uploadFile.ListItemAllFields["DocType"] = "Favourites";
    
    uploadFile.ListItemAllFields.Update();
    clientContext.ExecuteQuery();
    
    }
    }
            /// <summary>
            /// Sharepoint Client Create Folder by Folder name string
            /// </summary>
            public static void CreateFolder(ClientContext oContext, FolderCollection collFolder, string newSiteUrl, string folderStr, string strURL, string strFileName)
            {
                try
                {
                    string[] folders = folderStr.Split('/');
                    string FolderStr = string.Empty;
                    foreach (string folder in folders)
                    {
                        if (!string.IsNullOrEmpty(folder))
                        {
                            FolderStr += folder;
                            Folder folderNew = collFolder.Add(newSiteUrl + DocumentlistName + "/" + FolderStr);
                            oContext.Load(folderNew);
                            oContext.ExecuteQuery();
                            FolderStr += "/";
                        }
                    }
                }
                catch (Exception ex)
                {
                    //ログ出力
                    OutputDocumentErrorLog(strFileName, strURL, string.Empty,
                                ex.ToString(), errorLogPath, errorLorName);
                }
    
            }
                                    string newSiteUrl = ConfigurationManager.AppSettings["siteUrlNew"] ;using (ClientContext oContext = new ClientContext(newSiteUrl))
                                    {
                                        oContext.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["userNameNew"], 
                                      ConfigurationManager.AppSettings["passwordNew"], ConfigurationManager.AppSettings["domainNew"]); Web web = oContext.Web; FolderCollection collFolder = web.Folders; oContext.Load(collFolder); oContext.ExecuteQuery();
                                    string folderStr = folderServerRelativeUrl + listName + serverRelativeUrlOld; CreateFolder(oContext, collFolder, newSiteUrl, folderStr, strURL, strFileName); }
  • 相关阅读:
    20145334赵文豪 《信息安全系统设计基础》第2周学习总结
    20145334赵文豪《信息安全系统设计基础》第1周学习总结
    关于第五周大家学习问题的总结
    20145334 第五次 java 实验报告
    20145334 《Java程序设计》第10周学习总结
    实验四 Android开发基础
    # 20145334 《Java程序设计》第9周学习总结
    20145334实验三《敏捷开发与XP实践》
    实验二:面向对象设计
    程序的机器级表示内容补充及扩展
  • 原文地址:https://www.cnblogs.com/wodegui/p/4885196.html
Copyright © 2011-2022 走看看