var siteUrl = "https://mycompany.sharepoint.com/sites/my-site"; var folderPath = "/Shared Documents/Clients"; var fileName = "Proposal.docx"; var fileContentStream = new MemoryStream(File.ReadAllBytes("Proposal.docx")); var ctx = new ClientContext(siteUrl); var web = ctx.Web; var folder = web.GetFolderByServerRelativeUrl(folderPath); var fileCreationInformation = new FileCreationInformation { ContentStream = fileContentStream, Url = fileName, Overwrite = true }; var file = folder.Files.Add(fileCreationInformation); ctx.Load(file); ctx.ExecuteQuery();
var connectionString = "mongodb://localhost:27017"; var databaseName = "mydb"; var collectionName = "documents"; var fileName = "Report.pdf"; var fileContentStream = new MemoryStream(File.ReadAllBytes("Report.pdf")); var client = new MongoClient(connectionString); var database = client.GetDatabase(databaseName); var collection = database.GetCollectionPackage library: MongoDB.Driver.Core(collectionName); var document = new BsonDocument { { "name", fileName }, { "type", "pdf" }, { "content", new BsonBinaryData(fileContentStream) } }; collection.InsertOne(document);