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);

                                }
时间: 2024-07-31 08:23:00

SharePoint Client Add Folder,file to Library的相关文章

Sharepoint client model 中出现Cannot invoke HTTP DAV request. There is a pending query 的解决办法

由于近期在某项目中使用sharepoint client 对象模型做项目 在sharepoint 2010环境下正常,但迁移到sharepoint 2013后报错,提示如下 Cannot invoke HTTP DAV request ,there is a pending query 后经过查询微软官网提示说 这是由于客户端已经挂起了上下文请求, 于是处理如下 在报错代码前面添加 if(clientext.HasPendingRequest) { clienttext.ExecuteNoque

SharePoint Client Object Model API 介绍以及工作原理解析

COM和ServerAPI 的对比 SharePoint从2010开始引入了Client Object Model的API(后文中用COM来代替),从名字来看,我们可以简单的看出,该API是面向客户端的应用程序的.有这个这套API,使得所有SharePoint的终端用户 可以开发自己的应用程序来访问,修改SharePoint.下面的列表简述了COM和Server API的区别:   COM Server 运行端 可以在任何能够访问SharePoint的机器上运行 可以再浏览器上,.Net应用程序

Android问题集锦之四十九:Can&#39;t add XStream file dependency to Android Studio project

将xstream1.4.8 引入Android Strudio项目中,编译报错如下: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472) at

sharepoint 迁出文档时报错:sharepoint 服务器错误:the file &quot;xxxxxxxxx&quot; is not checked out

迁出文档时报错:sharepoint 服务器错误:the file "xxxxxxxxx" is not checked out 当文档库启用了历史版本,并且启用了:Create major and minor (draft) versions 当文档是draft的时候,无法迁出,将文档pubulish a major version,可以正常迁出.

Add a file to a Document Library and update metadata properties in a single method添加文档的方法

private void AddFileToDocumentLibrary(string documentLibraryUrl, string filename, byte[] file_bytes, string itemTitleText) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(documentLibraryUrl)) { using (SPWeb web = s

SharePoint 2013 Create Folder with conententtype programer

记录一下昨天写的SharePoint tool,需求是这样的: 在SharePoint list subfolder 下创建1000个folder,这些folder指定特殊的contenttype,contenttype中有一个Taxonomy类型的field,为这个filed赋值,并且新创建的这些folder下只能创建指定contenttype的file. 创建folder的代码如下: public static void CreatFolder(string siteUrl)//传入site

add swap file if you only have 1G RAM

dd if=/dev/zero of=/swapfile1 bs=1024 count=524288 mkswap /swapfile1 swapon /swapfile1 vi /etc/fstab # edit /etc/fstab file, add the following line /swapfile1 none swap sw 0 0 # save and quit free -m swapon -s 原文地址:https://www.cnblogs.com/otfsenter/p

node 上传文件 http client to post file

node做http client 发送post数据是很容易的事情,但要上传文件就不是太容易了主要是因为上传文件的报文和普通post是不太一样的 要了解http post可以看下这个 https://imququ.com/post/four-ways-to-post-data-in-http.html npm上封装好的第三方库很多 比如request,我们来看下自己实现需要怎么做 首先要声称个随机串,这个是用来做分段的标记 var boundaryKey = Math.random().toStr

Open any local folder/file in IE11 (and more) using MSHH

-------------------Poc.html------------------------ <OBJECT classid="clsid:52a2aaae-085d-4187-97ea-8c30db990436" width=100% height=100%> <PARAM name="Command" value="Index"> <PARAM name="Item1" value=