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

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

  1. [sharepoint]修改Item或者File的Author和Editor

    写在前面 最近项目中调用sharepoint rest api方式获取文件或者Item列表,而用的方式是通过证书请求,在上传文件,或者新建item的时候,默认的用户是在sharepoint端注册的用户 ...

  2. How to Get SharePoint Client Context in SharePoint Apps (Provider Hosted / SharePoint Access ) in CSOM (Client Side Object Model)

    http://www.codeproject.com/Articles/581060/HowplustoplusGetplusSharePointplusClientplusContex Downlo ...

  3. PostgreSQL Client Authentication Configuration File

    PostgreSQL: Documentation: 10: 16.4. Installation Procedure https://www.postgresql.org/docs/10/stati ...

  4. c# sharepoint client object model 客户端如何创建中英文站点

    c# sharepoint client object model 客户端如何创建中英文站点 ClientContext ClientValidate = tools.GetContext(Onlin ...

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

    由于近期在某项目中使用sharepoint client 对象模型做项目 在sharepoint 2010环境下正常,但迁移到sharepoint 2013后报错,提示如下 Cannot invoke ...

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

    CSOM和ServerAPI 的对比 SharePoint从2010开始引入了Client Object Model的API(后文中用CSOM来代替),从名字来看,我们可以简单的看出,该API是面向客 ...

  7. 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, ...

  8. SharePoint 2013 Create Folder with conententtype programer

    记录一下昨天写的SharePoint tool,需求是这样的: 在SharePoint list subfolder 下创建1000个folder,这些folder指定特殊的contenttype,c ...

  9. SharePoint Config database Log file too big – reduce it!

    SharePoint Config database logs are one thing to keep an eye on since they do have a tendency to gro ...

随机推荐

  1. Codeforces Round #325 (Div. 2) D. Phillip and Trains BFS

    D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/ ...

  2. Custom-Progress-Dialog-Android

    https://github.com/ManolescuSebastian/Custom-Progress-Dialog-Android

  3. 使用android x86进行android应用开发.

    首发论坛 安卓巴士.id:android_bin 一.必备工具: 1.虚拟机软件(本文使用virtual Box为例), 2.android x86镜像,下载地址http://www.android- ...

  4. MyEclipse 10官网下载地址以及破解方法

    刚刚公布了MyEclipse 10,我如今用的还是6.5的版本号,6.5的版本号是我认为最好用的一个版本号. 我装上了,还没感受到有哪些好用,就是感觉体积庞大,和IBM 的WID一样,是个多面手,啥事 ...

  5. python内存管理

    python对象三要素: identity(值):对应于内存的地址,不可修改 type(类型):不可修改 value(值): mutable :可以修改 immutable:不可以修改 引用计数 当引 ...

  6. 初探 MySQL 的 Binlog

    https://xcoder.in/2015/08/10/mysql-binlog-try/

  7. 分布式应用处理方式 - Remoting

    分布式应用程序 所谓分布式计算是一门计算机科学,它研究如何把一个需要非常巨大的计算能力才能解决的问题分成许多小的部分,然后把这些部分分配给许多计算机进行处理,最后把这些计算结果综合起来得到最终的结果. ...

  8. javascript笔记04:let语句 和 yield语句 和 with语句

    1.yield语句: <script type="application/javascript; version=1.7"> function generator() ...

  9. C语言---注释

    1.单行注释 //注释内容 2.多行注释 /*注释内容*/ 3.#if 0 注释内容 #endif 说明: 1.单行注释//不通用,有些编译器不支持 2.多行注释不能嵌套 3.#if 0 #endif ...

  10. [转]Oracle字符串拼接的方法

    本文转自:http://www.blogjava.net/liuwuping12064915/archive/2011/06/27/353096.html 和其他数据库系统类似,Oracle字符串连接 ...