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); }
  • 相关阅读:
    提高你的Java代码质量吧:使用构造函数协助描述枚举项
    Python文件或目录操作的常用函数
    汉语-词语:胸怀
    汉语-词语:胸襟
    汉语-词语:谋略
    汉语-词语:气量
    植物-常见树木:刺槐
    植物-常见树木:楝
    HDU 2255 奔小康赚大钱 KM算法题解
    Dozer--第三方复制工具,哎哟,还不错!
  • 原文地址:https://www.cnblogs.com/wodegui/p/4885196.html
Copyright © 2011-2022 走看看