在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
try
{ String fileToUpload = "C:\test.txt"; String sharePointSite = "http://localhost:80/"; String documentLibraryName = "test"; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite oSite = new SPSite(sharePointSite)) { using (SPWeb oWeb = oSite.RootWeb) { oWeb.AllowUnsafeUpdates = true; if (!System.IO.File.Exists(fileToUpload)) throw new Exception("File not found."); SPDocumentLibrary myLibrary = oWeb.Lists[documentLibraryName] as SPDocumentLibrary; // Prepare to upload Boolean replaceExistingFiles = true; String fileName = System.IO.Path.GetFileName(fileToUpload); FileStream fileStream = File.OpenRead(fileToUpload); // Upload document SPFile spfile = myLibrary.RootFolder.Files.Add(oWeb.Url.ToString() + "/" + myLibrary.Title.ToString() + "/" + fileNameWithoutExt + fileExtName, fileStream, replaceExistingFiles); // Commit spfile.Update(); myLibrary.Update(); oWeb.Update(); oWeb.AllowUnsafeUpdates = false; } } }); } catch (Exception SPError) { Response.Write(SPError.Message); } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论