zoukankan      html  css  js  c++  java
  • C# sharepoint 上传文件

    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string strUserName = "123123312312";
                string fileUrl = "D:/build/1/msssql.jar";
                 byte[] fileArray= AuthGetFileData(fileUrl);
                string fileName = "ss.doc";
                string targetFolder = "Shared Documents/General";
                string strPassword = "234123123";
                SecureString ssPwd = new SecureString();
                strPassword.ToList().ForEach(ssPwd.AppendChar);
                SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(strUserName, ssPwd);
                ClientContext context = new ClientContext("https://aiqweqwem.sharepoint.com/sites/IRqweqweqweqweata");
                context.Credentials = credentials;
                context.ExecuteQuery();
                UploadFile(context, targetFolder, fileName, fileArray);
    
                Web web = context.Web;
    
                context.Load(web);
    
                context.ExecuteQuery();
    
                Console.WriteLine(web.Title);
                Console.ReadKey();
    
            }
            public static void UploadFile(ClientContext context, string targetFolder, string fileName, byte[] fileArray)
            {
         
                Web web = context.Web;
               
                Folder docSetFolder = web.GetFolderByServerRelativeUrl(targetFolder);
                context.Load(docSetFolder);
                context.ExecuteQuery();
                string documentUrl = targetFolder + "/" + fileName;
                FileCreationInformation fci = new FileCreationInformation();
                fci.Url = documentUrl;
                fci.Content = fileArray; //byte[] take your stream and convert to byte array
                //get the folder's file collection
                FileCollection documentFiles = docSetFolder.Files;
                context.Load(documentFiles);
                context.ExecuteQuery();
                File newFile = documentFiles.Add(fci);
                context.Load(newFile);
                ListItem item = newFile.ListItemAllFields;
                context.Load(item);
                //start setting metadata here
                string contentTypeId = string.Empty;
                item["ContentTypeId"] = contentTypeId;
                item.Update();
                context.ExecuteQuery();
    
    
    
            }
      
    
        }
    }
  • 相关阅读:
    reuire代码优化之:r.js
    项目伪模块化开发之:requirejs(AMD)开发
    cookie
    前端构建工具gulpjs的使用介绍及技巧
    js之:漂浮线
    同步对象(Event)
    并发&并行 同步&异步 GIL 任务 同步锁 死锁 递归锁
    进程 线程 threading模块
    认证客户端的链接合法性
    socketserver 模块的构成
  • 原文地址:https://www.cnblogs.com/funkboy/p/14184169.html
Copyright © 2011-2022 走看看