• 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学习之实例变量初始化
    rip中的连续子网以及不连续子网
    扫描工具
    WScript.SendKeys()的sendkeys发送组合键以及特殊字符
    sql 查询包含字符的数量统计
    leetcode题1Two sum 练习
    vs 2015密钥
    前端 边界圆角
    前端 字体样式
    前端 高级选择器 伪类选择器
  • 原文地址:https://www.cnblogs.com/wodegui/p/4885196.html
Copyright © 2020-2023  润新知