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 ...
随机推荐
- Android选择系统相册或拍照上传
PhotoUtils.rar
- android学习日记07--Canvas画布
1.Canvas Canvas类主要实现了屏幕的绘制过程,其中包含了很多实用的方法,比如绘制一条路径.区域.贴图.画点.画线.渲染文本,当然Android官网提示大家很多方法有不同的重载版本,参数更灵 ...
- firefly的rpc。。
firefly使用了twisted的pb 来实现rpc: http://twistedmatrix.com/documents/current/core/howto/pb-usage.html 服务端 ...
- [原创]如何写好SqlHelper
所有写数据库应用的都会遇到SqlHelper.每个人实现的也不同,网上现成的例子也很多.但在实际操作中,大部分都不实用.什么样的才是实用的?答:适合应用场景的! 下面来介绍下我写的一个关于Oracle ...
- Java基础知识强化之IO流笔记67:Properties的特殊功能使用
1. Properties的特殊功能 public Object setProperty(String key,String value):添加元素 public String getProperty ...
- Find security bugs学习笔记V1.0
Find security bugs学习笔记V1.0 http://www.docin.com/p-779309481.html
- 常用CentOS 6/7 扩展源
1.系统自带 baseextrasupdates 2.epel yum install epel-release https://fedoraproject.org/wiki/EPEL 3.el(用于 ...
- 关于国际化中的$NON-NLS-1$
百度百科解释: 这实际与eclipse中支持i18n的一种方式,eclipse的标准结构,将所有string常量定义到·properties中,例如下面程序段中的TestRef.hello实际上是·p ...
- 【二分答案+贪心】UVa 1335 - Beijing Guards
Beijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City ...
- 从lambda到函数式编程
Object.send(:remove_const,'TRUE') Object.send(:remove_const,'FALSE') def to_integer(pro) pro[-> n ...