SharePoint2013 上传文件到文档库
Posted lishidefengchen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SharePoint2013 上传文件到文档库相关的知识,希望对你有一定的参考价值。
SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID]) { web.AllowUnsafeUpdates = true; SPList list = web.Lists.TryGetList("文档"); //考虑到中英文的影响,这个在英文状态下名称可能需要改变 if (list != null) { LogHelper.WriteLog(LogArea.SPSUI, LogLevelType.INFO, "资产处置-找到文档库"); SPFolder folder = list.RootFolder; HttpFileCollection files = Request.Files; if (files.Count > 0 && fileUpload.HasFile) { 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(); File fileModel = new File { Id = Guid.NewGuid(), Name = onlyName, Url = oFile.ServerRelativeUrl, Created = DateTime.Now, CreateBy = web.CurrentUser.Name }; result.Add(fileModel); } } } web.AllowUnsafeUpdates = false; } } });
以上是关于SharePoint2013 上传文件到文档库的主要内容,如果未能解决你的问题,请参考以下文章