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;
 }