public static SPFile UploadStream(SPDocumentLibrary library, Stream stream, string fileName) { library.RequireNotNull("library"); stream.RequireNotNull("stream"); fileName.RequireNotNullOrEmpty("fileName"); SPFolder rootFolder = library.RootFolder; SPFile spFile = rootFolder.Files.Add(fileName, stream); library.Update(); return spFile; }
public static SPFile UploadFromPath(SPDocumentLibrary library, string path, string fileName) { library.RequireNotNull("library"); path.RequireNotNullOrEmpty("path"); fileName.RequireNotNullOrEmpty("fileName"); using (Stream stream = File.OpenRead(path)) { return UploadStream(library, stream, fileName); } }