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. Tomcat 生产服务器性能优化

    虑一下这种场景,你开发了一个应用,它有十分优秀的布局设计,最新的特性以及其它的优秀特点.但是在性能这方面欠缺,不管这个应用如何都会遭到客户拒绝.客户总是期望它们的应用应该有更好的性能.如果你在产品中使 ...

  2. [React Fundamentals] Owner Ownee Relationship

    The owner-ownee relationship is used to designate a parent-child relationship with React components ...

  3. QT5中如何自定义窗口部件

    提升法 eg.(定义一个新的QLable部件)1.定义一个类class Label : public base, public QLabel //可以支持多重继承2.在qt creator中打开ui编 ...

  4. js用斜率判断鼠标进入div的四个方向

    网上大部分判断鼠标移入div移入移出都是使用一下方法: 这个方法确实十分奇特,使用起来十分方便. 后来自己看了一些文章,看到有另一种以斜率的方法来判断鼠标的移动方向. 上图是此方法的示意图,以浏览器左 ...

  5. ios 通过代码调节屏幕亮度

    方法: [[UIScreen mainScreen] setBrightness: value]; value:value就是屏幕的亮度值  这个值介于0和1之间 另外 这个方法  会即时刷新  无需 ...

  6. [置顶] c++类的继承(inheritance)

    在C++中,所谓"继承"就是在一个已存在的类的基础上建立一个新的类.已存在的类(例如"马")称为"基类(base class )"或&quo ...

  7. signal函数、sigaction函数及信号集(sigemptyset,sigaddset)操作函数

    信号是与一定的进程相联系的.也就是说,一个进程可以决定在进程中对哪些信号进行什 么样的处理.例如,一个进程可以忽略某些信号而只处理其他一些信号:另外,一个进程还可以选择如何处理信号.总之,这些总与特定 ...

  8. 关于 ASP.NET vNext

    ASP.NET vNext 最大的特性就是跨平台(基于 Mono 运行时),试想下:作为.NET程序员,终于不被Java或C++程序员挑自己的短板,确实是蛮振奋人心的.当然,除了跨平台,使用 Rosl ...

  9. RavenScheme简介

    RavenScheme简介 RavenScheme使用了一个运行『读入-求值-打印』循环的解释器.该解释器从标准输入反复的读入表达式,对得到的表达式求值,然后打印出结果. 如果用户键入: [加 1 2 ...

  10. 使用jQuery获取Bootstrap Switch的值

    $('#switcher').bootstrapSwitch('state'); // true || false $('#switcher').bootstrapSwitch('toggleStat ...