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); }
SharePoint Client Add Folder,file to Library的更多相关文章
- [sharepoint]修改Item或者File的Author和Editor
写在前面 最近项目中调用sharepoint rest api方式获取文件或者Item列表,而用的方式是通过证书请求,在上传文件,或者新建item的时候,默认的用户是在sharepoint端注册的用户 ...
- 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 ...
- PostgreSQL Client Authentication Configuration File
PostgreSQL: Documentation: 10: 16.4. Installation Procedure https://www.postgresql.org/docs/10/stati ...
- c# sharepoint client object model 客户端如何创建中英文站点
c# sharepoint client object model 客户端如何创建中英文站点 ClientContext ClientValidate = tools.GetContext(Onlin ...
- Sharepoint client model 中出现Cannot invoke HTTP DAV request. There is a pending query 的解决办法
由于近期在某项目中使用sharepoint client 对象模型做项目 在sharepoint 2010环境下正常,但迁移到sharepoint 2013后报错,提示如下 Cannot invoke ...
- SharePoint Client Object Model API 介绍以及工作原理解析
CSOM和ServerAPI 的对比 SharePoint从2010开始引入了Client Object Model的API(后文中用CSOM来代替),从名字来看,我们可以简单的看出,该API是面向客 ...
- 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, ...
- SharePoint 2013 Create Folder with conententtype programer
记录一下昨天写的SharePoint tool,需求是这样的: 在SharePoint list subfolder 下创建1000个folder,这些folder指定特殊的contenttype,c ...
- 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 ...
随机推荐
- HubbleDotNet 学习之路
1.创建后台任务实现自动同步更新表数据.打开工具后点击“management”选项卡,选择“task scheduler management”,在弹出的窗口中点击右侧的"add" ...
- Rank of Tetris(hdu1811拓扑排序+并查集)
题意:关于Rating的信息.这些信息可能有三种情况,分别是"A > B","A = B","A < B",分别表示A的Rati ...
- android Animation 动画效果介绍
Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动 ...
- Helpers\CSRF
Helpers\CSRF CSRF Protection The CSRF helper is used to protect post request from cross site request ...
- Models
Models Models control the data source, they are used for collecting and issuing data, this could be ...
- Wireshark 过滤条件
做应用识别这一块经常要对应用产生的数据流量进行分析. 抓包采用wireshark,提取特征时,要对session进行过滤,找到关键的stream,这里总结了wireshark过滤的基本语法,供自己以后 ...
- 【排障】Outlook Express 2G收件箱大小限制
Outlook Express 2G收件箱大小限制 文:铁乐猫 ----------------------------- Outlook Express(以下简称OE)客户端收件箱大于或接近2G时, ...
- git 配置用户名和邮箱
在安装了git for windows之后,个人总是忘记配置git config的命令,以此记录一下: 配置用户名和邮箱的命令 git config --global user.name " ...
- 使用Log4Net发送日志邮件 (转载)
前言 公司前几天重新确立了考核指标,主要是针对我们研发部,而我们的经理要求也高,对我们绩效考核扣分也挺狠的,100分的,出了几个严重bug就变 0分,反正只要被用户发现并且提出来了,就会扣分,没被用户 ...
- xml的语法与创建
xml语法很简单,但很严格,如果出现错误则不能正常解析,而HTML如果出现局部的错误,照样解析 xml第一行必须写xml头<?xml version='1.0' encoding='utf8'? ...