4
votes

I am creating Schema using Core Service in SDL Tridion 2011 SP1. In the creation of the Schema I have used the custom namespace URI for the Schema. Generally when we create a Schema through Tridion CME directly, we will get a namespace URI generated automatically starting with uuid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have used this code to create a Schema:

Tridion.ContentManager.CoreService.Client.SchemaData schemas = new SchemaData
{
    Title = "coreservicesschema3",
    Description = "coreservicesschema",
    Id = "tcm:0-0-0",
    LocationInfo = new LocationInfo
    {
        OrganizationalItem =
            new LinkToOrganizationalItemData { IdRef = "tcm:7-18-2" }
    },

    RootElementName = "Content",
    NamespaceUri = "customnamespaceuri",
    Xsd = xsd.ToString(SaveOptions.None)
};
schemas = (SchemaData)client.Create(schemas, new ReadOptions());
Response.Write("<BR>" +"new schema id"+ schemas.Id);
Response.Write("<BR>" + "new schema Name" + schemas.Title);
//schema created

Can anyone indicate how to create a Schema with default namespace URI?

Thank you

1

1 Answers

6
votes

The minimal code you need in order to create a Schema with Core Service is the following:

using (var client = new SessionAwareCoreServiceClient(netTcpBinding, remoteAddress))
{
    SchemaData schemaData = client.GetDefaultData(ItemType.Schema, folderId) as SchemaData;
    schemaData.Description = "description";
    schemaData = client.Save(schemaData, readOptions) as SchemaData;
    schemaData = client.CheckIn(schemaData.Id, readOptions) as SchemaData;

    Console.WriteLine("Schema: " + schemaData.LocationInfo.WebDavUrl);
}

The Schema will be created with the default namespace. In the case of this example, it will also not contain any fields, but that's not what you were asking for.