.NET Example of Creating a Tag

This example is based on code in the TaggingWorkflow.cs sample file.

This example creates a tag specification and then uses it to create the tag. The tag specification references the category identifier that was returned from the category create operation. Use the returned tag identifier for subsequent operations on the tag.

This example is based on the information that is provided in Creating a Tag.

Note: For a complete and up-to-date version of the sample code, see the vSphere Automation SDK .NET samples at GitHub.
...
 
var tagStub = myStubFactory.CreateStub<Tag>(myStubConfiguration);
 
// Set up a tag create spec.
var createSpec = new TagTypes.CreateSpec();
createSpec.SetName(“red”);
createSpec.SetDescription(“My favorite color”);
createSpec.SetCategoryId(newCategoryId);
 
String tagId = tagStub.Create(spec);