This example shows how to upload a file from a URL to a library item.

This example uses the steps that are described in the Upload a File from a URL to a Library Item procedure.

....
using vmware.content;
using vmware.content.library;
using vmware.content.library.item;
using vmware.content.library.item.updatesession;
...
// Create a new library item. See Create an Empty Library Item.
 
...
 
// Create an UpdateSessionModel instance to track the changes you make to the item.
var updateSessionModel = new UpdateSessionModel();
updateSessionModel.SetLibraryItemId(newItem);
 
// Create a new update session.
var uploadService = ServiceManager.VapiConnection.GetService<UpdateSession>();
var sessionId = uploadService.Create(Guid.NewGuid().ToString(), updateSessionModel);
 
// Create a new AddSpec instance to describe the properties of the file to be uploaded.
var fileSpec = new vmware.content.library.item.updatesession.FileTypes.AddSpec();
fileSpec.SetName("ESXi patch as of 10/2/2015");
fileSpec.SetSourceType(vmware.content.library.item.updatesession.FileTypes.SourceType.PULL);
 
// Specify the location from which the file is uploaded to the library item.
var endpoint = new TransferEndpoint();
endpoint.SetUri(new Uri("http://www.acme.com/patches_ESXi55/ESXi_patch.iso"));
fileSpec.SetSourceEndpoint(endpoint);
var uploadFileService = ServiceManager.VapiConnection.GetService<vmware.content.library.item.updatesession.File>();
uploadFileService.Add(sessionId, fileSpec);
 
// Mark the session as completed.
uploadService.Complete(sessionId);