zoukankan      html  css  js  c++  java
  • Upload document to SharePoint document library Using C# (CSOM)

    if (context.Request.Files.Count > 0)
    {
    string strUrl = "http://XXXXXXXXXXX:8080/sites/home";
    Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate ()
    {
    using (SPSite site = new SPSite(strUrl))
    {
    using (SPWeb web = site.OpenWeb(""))
    {
    web.AllowUnsafeUpdates = true;
    SPList list = web.Lists["文档"]; //考虑到中英文的影响,这个在英文状态下名称可能需要改变

                            if (list != null)
                            {
                                SPFolder folder = list.RootFolder;
                                HttpFileCollection files = context.Request.Files;
                                if (files.Count > 0)
                                {
                                    for (int i = 0; i < files.Count; i++)
                                    {
                                        HttpPostedFile file = files[i];
                                        string onlyName = System.IO.Path.GetFileName(file.FileName);
                                        string urlOfFile = DateTime.Now.ToString("yyyyMMddhhmmss") + onlyName;
                                        SPFile oFile = folder.Files.Add(urlOfFile, file.InputStream, true);
                                        oFile.Update();
                                    }
                                }
                            }
                            web.AllowUnsafeUpdates = false;
                        }
                    }
                });
    
                context.Response.Write("Success");
            }
            else
            {
                context.Response.Write("没有数据");
            }
    幸福是一件礼物,得到它的秘诀是不怀期待,只在它来的时候尽情享受
  • 相关阅读:
    Python 基础(二)
    Python 入门
    DNS
    PXE自动化安装CentOS7和CentOS6
    AIDE及sudo应用
    SSH应用
    KickStart自动化安装Linux
    初见鸟哥
    数组ARRAY
    SSH用法
  • 原文地址:https://www.cnblogs.com/selenazhou/p/14389078.html
Copyright © 2011-2022 走看看