This example shows how to upload an ISO image file from the local system to a library item.

This example uses the steps that are described in the Upload a File from a Local System 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 as described in .NET Example of Creating a 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>();
String sessionId = uploadService.Create(Guid.NewGuid().ToString(), updateSessionModel);
try
{
    // Instantiate the vmware.vcloud.suite.samples.common.HttpHelper class.

    var httpClient = new HttpClient(true);

    // 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.PUSH);
    var uploadFileService = ServiceManager.VapiConnection.GetService<vmware.content.library.item.updatesession.File>();
    var fileInfo = uploadFileService.Add(sessionId, fileSpec);
    var uploadUri = fileInfo.GetUploadEndpoint().GetUri();
    var file1 = System.IO.File.Create("/updates/esxi/esxi_patch.iso");

    // Use the HTTP PUT request to upload the file to the library item.
    httpClient.Upload(file1, uploadUri.ToString());

    // Mark the upload session as completed.
    uploadService.Complete(sessionId);
}
finally
{
    uploadService.Delete(sessionId);
}