Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8488877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:40:19+00:00 2026-06-10T21:40:19+00:00

I am creating Multimedia components using core service and everything is working fine. But

  • 0

I am creating Multimedia components using core service and everything is working fine. But when Metadata schema fields are defined on the Multimedia schema using which I am creating my Multimedia components then I am getting following error:-

Unable to find http://www.tridion.com/ContentManager/5.0/DefaultMultimediaSchema:Metadata.

This message is displayed when I have given Default Multimedia schema’s TCM ID for Multimedia component. As metadata fields are saved in Tridion Database so I first have to retrieve these fields from broker or what is the best solution for this, please suggest. Below is the sample code. Please modify it if someone have any idea for providing default value for metadatafields and how to retrieve them (with/without querying broker DB):-

 public static string UploadMultiMediaComponent(string folderUri, string title, string schemaID)
    {
        core_service.ServiceReference1.SessionAwareCoreService2010Client client = new SessionAwareCoreService2010Client(); 
        client.ClientCredentials.Windows.ClientCredential.UserName = "myUserName"; 
        client.ClientCredentials.Windows.ClientCredential.Password = "myPassword"; client.Open();

        ComponentData multimediaComponent = (ComponentData)client.GetDefaultData(
                                             ItemType.Component, folderUri);
        multimediaComponent.Title = title;

        multimediaComponent.ComponentType = ComponentType.Multimedia;
        multimediaComponent.Schema.IdRef =schemaID;

        //multimediaComponent.Metadata = "";

        StreamUpload2010Client streamClient = new StreamUpload2010Client();

        FileStream objfilestream = new FileStream(@"\My Documents\images.jpg",
                                                  FileMode.Open, FileAccess.Read);
        string tempLocation = streamClient.UploadBinaryContent("images.jpg",
                                                               objfilestream);

        BinaryContentData binaryContent = new BinaryContentData();
        binaryContent.UploadFromFile = tempLocation;
        binaryContent.Filename = "images.jpg";
        binaryContent.MultimediaType = new LinkToMultimediaTypeData()
        {
            // for jpg file
            IdRef = "tcm:0-2-65544"
        };
        multimediaComponent.BinaryContent = binaryContent;

        IdentifiableObjectData savedComponent = client.Save(multimediaComponent,
                                                            new ReadOptions());

        client.CheckIn(savedComponent.Id, null);
        streamClient.Close();
        client.Close();
        Console.WriteLine(savedComponent.Id);
        //}
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:40:21+00:00Added an answer on June 10, 2026 at 9:40 pm

    I don’t know why your code not working but following code is working for me

    public static ComponentData GenerateMultiMediaComponent(TridionGeneration tridionGeneration, XmlData newsArticle, string componentName)
            {
                try
                {
                    Dictionary<string, object> dicTridion = Common.GetTridionObject(tridionGeneration.client, ItemType.Component, tridionGeneration.Settings.ComponentFolderUri, componentName);
                    int objectCount = (int)dicTridion["count"];
    
                    SchemaFieldsData schemaFields = tridionGeneration.client.ReadSchemaFields(tridionGeneration.Settings.SchemaUri, true, new ReadOptions());
    
    
    
    
                    ComponentData componentData = (ComponentData)tridionGeneration.client.GetDefaultData(ItemType.Component, tridionGeneration.Settings.ComponentFolderUri);
    
                    if (schemaFields.Fields != null)
                    {
                        var fields = Fields.ForContentOf(schemaFields);
                        Helper.FillSchemaFields(tridionGeneration, fields);
                        componentData.Content = fields.ToString();
                    }
    
                    if (schemaFields.MetadataFields != null)
                    {
                       var  metafields = Fields.ForMetadataOf(schemaFields, componentData);
                        Helper.FillSchemaFields(tridionGeneration, metafields);
                        componentData.Metadata = metafields.ToString();
                    }
    
                    componentData.Title = (objectCount == 0) ? componentName : componentName + " " + (objectCount + 1).ToString();
                    componentData.ComponentType = ComponentType.Multimedia;
    
                    StreamUpload2010Client streamClient = new StreamUpload2010Client();
    
                    FileStream objfilestream = new FileStream(@"[IMAGE_PATH]", FileMode.Open, FileAccess.Read);
                    string tempLocation = streamClient.UploadBinaryContent("images.jpg", objfilestream);
                    BinaryContentData binaryContent = new BinaryContentData();
                    binaryContent.UploadFromFile = tempLocation;
                    binaryContent.Filename = "[IMAGE_NAME]";
                    componentData.BinaryContent = binaryContent;
                    binaryContent.MultimediaType = new LinkToMultimediaTypeData()
                    {
                        IdRef = "tcm:0-2-65544"
                    };
    
                    componentData = (ComponentData)tridionGeneration.client.Create(componentData, new ReadOptions());
    
                    return componentData;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }
    

    Here is the Helper class:

    public static class Helper
        {
            public static void FillSchemaFields(TridionGeneration tridionGeneration, Fields fields)
            {
                List<XmlData> data = XmlHelper.xmlData;
    
                var ofield = fields.GetEnumerator();
                while (ofield.MoveNext())
                {
                    Field f = ofield.Current;
                    FillFieldValue(tridionGeneration, fields, f, data[0]);
                }
            }
    
            private static void FillFieldValue(TridionGeneration tridionGeneration, Fields fields, Field f, XmlData data)
            {
                if (f.Type == typeof(MultimediaLinkFieldDefinitionData))
                {
                    fields[f.Name].Value = tridionGeneration.Settings.DefaultImageUri;
                }
                else if (f.Type != typeof(EmbeddedSchemaFieldDefinitionData))
                {
                    foreach (XmlData fieldvalue in data.Attributes)
                    {
                        if (f.Type == typeof(DateFieldDefinitionData))
                        {
                            if (fieldvalue.text.ToLower() == f.Name.ToLower())
                            {
                                fields[f.Name].Value = Convert.ToDateTime(fieldvalue.value).ToString("yyyy-MM-ddTHH:mm:ss");
                            }
                            else
                            {
                                string val = FindSchemaValue(tridionGeneration, fieldvalue.Attributes, f.Name);
                                if (!string.IsNullOrEmpty(val))
                                {
                                    fields[f.Name].Value = Convert.ToDateTime(val).ToString("yyyy-MM-ddTHH:mm:ss");
                                }
                            }
                        }
                        else
                        {
                            if (fieldvalue.text.ToLower() == f.Name.ToLower())
                            {
                                fields[f.Name].Value = System.Net.WebUtility.HtmlEncode(fieldvalue.value);
                            }
                            else
                            {
                                string val = FindSchemaValue(tridionGeneration, fieldvalue.Attributes, f.Name);
                                if (!string.IsNullOrEmpty(val))
                                {
                                    fields[f.Name].Value = System.Net.WebUtility.HtmlEncode(val);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Fields fs = f.GetSubFields();
                    var ofield = fs.GetEnumerator();
                    while (ofield.MoveNext())
                    {
                        Field ff = ofield.Current;
                        FillFieldValue(tridionGeneration, fs, ff, data);
                    }
                }
            }
    
            private static string FindSchemaValue(TridionGeneration tridionGeneration, List<XmlData> data, string fieldname)
            {
                foreach (XmlData fieldvalue in data)
                {
                    if (fieldvalue.text.ToLower() == fieldname.ToLower())
                    {
                        return fieldvalue.value;
                    }
                    else
                    {
                        FindSchemaValue(tridionGeneration, fieldvalue.Attributes, fieldname);
                    }
                }
                return "";
            }
        }
    

    and the Fields class:

    public class Fields
        {
            private ItemFieldDefinitionData[] definitions;
            private XmlNamespaceManager namespaceManager;
    
            private XmlElement root; // the root element under which these fields live
    
            // at any point EITHER data OR parent has a value
            private SchemaFieldsData data; // the schema fields data as retrieved from the core service
            private Fields parent; // the parent fields (so we're an embedded schema), where we can find the data
    
            public Fields(SchemaFieldsData _data, ItemFieldDefinitionData[] _definitions, string _content = null, string _rootElementName = null)
            {
                data = _data;
                definitions = _definitions;
                var content = new XmlDocument();
                if (!string.IsNullOrEmpty(_content))
                {
                    content.LoadXml(_content);
                }
                else
                {
                    content.AppendChild(content.CreateElement(string.IsNullOrEmpty(_rootElementName) ? _data.RootElementName : _rootElementName, _data.NamespaceUri));
                }
                root = content.DocumentElement;
                namespaceManager = new XmlNamespaceManager(content.NameTable);
                namespaceManager.AddNamespace("custom", _data.NamespaceUri);
            }
            public Fields(Fields _parent, ItemFieldDefinitionData[] _definitions, XmlElement _root)
            {
                definitions = _definitions;
                parent = _parent;
                root = _root;
            }
    
            public static Fields ForContentOf(SchemaFieldsData _data)
            {
                return new Fields(_data, _data.Fields);
            }
            public static Fields ForContentOf(SchemaFieldsData _data, ComponentData _component)
            {
                return new Fields(_data, _data.Fields, _component.Content);
            }
            public static Fields ForMetadataOf(SchemaFieldsData _data, RepositoryLocalObjectData _item)
            {
                return new Fields(_data, _data.MetadataFields, _item.Metadata, "Metadata");
            }
    
            public string NamespaceUri
            {
                get { return data != null ? data.NamespaceUri : parent.NamespaceUri; }
            }
            public XmlNamespaceManager NamespaceManager
            {
                get { return parent != null ? parent.namespaceManager : namespaceManager; }
            }
    
            internal IEnumerable<XmlElement> GetFieldElements(ItemFieldDefinitionData definition)
            {
                return root.SelectNodes("custom:" + definition.Name, NamespaceManager).OfType<XmlElement>();
            }
            internal XmlElement AddFieldElement(ItemFieldDefinitionData definition)
            {
                var newElement = root.OwnerDocument.CreateElement(definition.Name, NamespaceUri);
    
                XmlNodeList nodes = root.SelectNodes("custom:" + definition.Name, NamespaceManager);
                XmlElement referenceElement = null;
                if (nodes.Count > 0)
                {
                    referenceElement = (XmlElement)nodes[nodes.Count - 1];
                }
                else
                {
                    // this is the first value for this field, find its position in the XML based on the field order in the schema
                    bool foundUs = false;
                    for (int i = definitions.Length - 1; i >= 0; i--)
                    {
                        if (!foundUs)
                        {
                            if (definitions[i].Name == definition.Name)
                            {
                                foundUs = true;
                            }
                        }
                        else
                        {
                            var values = GetFieldElements(definitions[i]);
                            if (values.Count() > 0)
                            {
                                referenceElement = values.Last();
                                break; // from for loop
                            }
                        }
                    } // for every definition in reverse order
                } // no existing values found
                root.InsertAfter(newElement, referenceElement); // if referenceElement is null, will insert as first child
                return newElement;
            }
    
            public IEnumerator<Field> GetEnumerator()
            {
                return (IEnumerator<Field>)new FieldEnumerator(this, definitions);
            }
            public Field this[string _name]
            {
                get
                {
                    var definition = definitions.First<ItemFieldDefinitionData>(ifdd => ifdd.Name == _name);
                    if (definition == null) throw new ArgumentOutOfRangeException("Unknown field '" + _name + "'");
                    return new Field(this, definition);
                }
            }
    
            public override string ToString()
            {
                return root.OuterXml;
            }
    
        }
    
        public class FieldEnumerator : IEnumerator<Field>
        {
            private Fields fields;
            private ItemFieldDefinitionData[] definitions;
    
            // Enumerators are positioned before the first element until the first MoveNext() call
            int position = -1;
    
            public FieldEnumerator(Fields _fields, ItemFieldDefinitionData[] _definitions)
            {
                fields = _fields;
                definitions = _definitions;
            }
    
            public bool MoveNext()
            {
                position++;
                return (position < definitions.Length);
            }
    
            public void Reset()
            {
                position = -1;
            }
    
            object IEnumerator.Current
            {
                get
                {
                    return Current;
                }
            }
    
            public Field Current
            {
                get
                {
                    try
                    {
                        return new Field(fields, definitions[position]);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
    
            public void Dispose()
            {
            }
        }
    
        public class Field
        {
            private Fields fields;
            private ItemFieldDefinitionData definition;
    
            public Field(Fields _fields, ItemFieldDefinitionData _definition)
            {
                fields = _fields;
                definition = _definition;
            }
    
            public string Name
            {
                get { return definition.Name; }
            }
            public Type Type
            {
                get { return definition.GetType(); }
            }
            public string Value
            {
                get
                {
                    return Values.Count > 0 ? Values[0] : null;
                }
                set
                {
                    if (Values.Count == 0) fields.AddFieldElement(definition);
                    Values[0] = value;
                }
            }
            public ValueCollection Values
            {
                get
                {
                    return new ValueCollection(fields, definition);
                }
            }
    
            public void AddValue(string value = null)
            {
                XmlElement newElement = fields.AddFieldElement(definition);
                if (value != null) newElement.InnerText = value;
            }
    
            public void RemoveValue(string value)
            {
                var elements = fields.GetFieldElements(definition);
                foreach (var element in elements)
                {
                    if (element.InnerText == value)
                    {
                        element.ParentNode.RemoveChild(element);
                    }
                }
            }
    
            public void RemoveValue(int i)
            {
                var elements = fields.GetFieldElements(definition).ToArray();
                elements[i].ParentNode.RemoveChild(elements[i]);
            }
    
            public IEnumerable<Fields> SubFields
            {
                get
                {
                    var embeddedFieldDefinition = definition as EmbeddedSchemaFieldDefinitionData;
                    if (embeddedFieldDefinition != null)
                    {
                        var elements = fields.GetFieldElements(definition);
                        foreach (var element in elements)
                        {
                            yield return new Fields(fields, embeddedFieldDefinition.EmbeddedFields, (XmlElement)element);
                        }
                    }
                }
            }
    
            public Fields GetSubFields(int i = 0)
            {
                var embeddedFieldDefinition = definition as EmbeddedSchemaFieldDefinitionData;
                if (embeddedFieldDefinition != null)
                {
                    var elements = fields.GetFieldElements(definition);
                    if (i == 0 && !elements.Any())
                    {
                        // you can always set the first value of any field without calling AddValue, so same applies to embedded fields
                        AddValue();
                        elements = fields.GetFieldElements(definition);
                    }
                    return new Fields(fields, embeddedFieldDefinition.EmbeddedFields, elements.ToArray()[i]);
                }
                else
                {
                    throw new InvalidOperationException("You can only GetSubField on an EmbeddedSchemaField");
                }
            }
            // The subfield with the given name of this field
            public Field this[string name]
            {
                get { return GetSubFields()[name]; }
            }
            // The subfields of the given value of this field
            public Fields this[int i]
            {
                get { return GetSubFields(i); }
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating the closure is easy but using it is confusing for me. Here is
Creating a website using simple html(not html5) and css but got stock in mouseover
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating a simple RPG game, first time using XNA. Trying to get my character
Error creating bean with name 'sessionFactory' defined in class path resource [ApplicationContext.xml]: Invocation of
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
Creating a table without tbody using javascript createElement/appendChild will not add tbody in Firebug
Creating sprite sheets aka texture atlases rather than using many hundres of individual images
Creating extensions got much easier with Vs2010, but this seems not to be the
Creating a site in with FrogCMS and using alot of jquery to create an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.