.NET Example of Changing the Settings for a Library Item

This example shows how to find an item by using the item name and then how to change the name and description of the retrieved item.
This example uses the steps that are described in the Edit the Settings of a Library Item procedure.
For related code samples, see the vSphere Automation SDK .NET samples at GitHub.
... var libItemService = ServiceManager.VapiConnection.GetService<Item>(); var itemFilesService = ServiceManager.VapiConnection.GetService< vmware.content.library.item.File>(); // List the items in a published library foreach (var itemId in libItemService.List(libraryId)) { // List the files uploaded to each library item and print their names and size foreach (var singleFile in itemFilesService.List(itemId)) { Console.WriteLine("Library item with name " + singleFile.GetName() + " has size " + singleFile.GetSize()); } // Change the name and description of the library item with the specified name var singleItem = libItemService.Get(itemId); if (singleItem.GetName().Equals("simpleVmTemplate")) { var libItemUpdated = new ItemModel(); libItemUpdated.SetName("newItemName"); libItemUpdated.SetDescription("Description of the newItemName"); libItemService.Update(singleItem.GetId(), libItemUpdated); } }