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) B. Laurenty and Shop 前缀和

    B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...

  2. [置顶] Java编程笔试题之一 ----文件操作

    题目:给定一个文件和一个字符串,判断文件是否包含该字符串,如果包含,请打印出包含该字符串的行号以及该行的全部内容. 思路: ①使用缓冲流(BufferedReader)读取文件,定义初始行号为0.   ...

  3. hdu4081 次小生成树变形

    pid=4081">http://acm.hdu.edu.cn/showproblem.php?pid=4081 Problem Description During the Warr ...

  4. 使用pypi镜像源加速第三方库在线安装

    用easy_install和pip来安装第三方库很方便 它们的原理其实就是从Python的官方源pypi.python.org/pypi 下载到本地,然后解包安装. 不过因为某些原因,访问官方的pyp ...

  5. Js 替代

    替代全部:.replace(/#/g,"/") 替代第一个:.replace("#","/")    var regS = new RegE ...

  6. Windows2012中Jenkins搭建.NET自动编译测试与发布环境

    安装7Zip 下载地址: http://www.7-zip.org/a/7z1602-x64.exe 安装Git 下载地址:https://github.com/git-for-windows/git ...

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

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

  8. [转]Oracle ORA-01403: no data found Exception SYS_REFCURSOR

    本文转自:http://stackoverflow.com/questions/9104153/what-is-the-correct-way-to-deal-with-this-oracle-ora ...

  9. hdu 1092 A+B for Input-Output Practice (IV)

    A+B for Input-Output Practice (IV) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  10. MySQL常用查询

    显示所有数据库 show datebases; 删除数据库 drop datebase dbName 创建数据库 create datebase [if not exists] dbName; //中 ...