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); }
  • 相关阅读:
    Infosec institute n00bs CTF writeup
    CTF学习之CODE
    ThinkPHP函数详解:C方法
    流程控制的替代语法
    Jquery DOM
    YII2 请求(request)
    YII2 运行概述(Overview)
    YII2 小部件(widgets)
    YII2 过滤器 filters
    YII2 随笔 视图最佳实践
  • 原文地址:https://www.cnblogs.com/wodegui/p/4885196.html
Copyright © 2011-2022 走看看