user1373140
user1373140

Reputation: 489

Updating multimedia component using TOM.NET

I am trying to update the metadata on the multimedia image in C# using Tridion's TOM.NET API like this

 componentMM.LoadXML(localComponent.GetXML(XMLReadFilter.XMLReadALL));
 // make changes to the component mm multimedia text;
 localComponent.UpdateXML(componentMM.InnerXML);
 localComponent.Save(True)

While this works for other components, it is failing for Multimedia images.

<?xml version="1.0"?>
<tcm:Error xmlns:tcm="http://www.tridion.com/ContentManager/5.0" 
           ErrorCode="80040345" Category="19" Source="Kernel" Severity="2">
    <tcm:Line ErrorCode="80040345" Cause="false" MessageID="16137"><![CDATA[ 

    Unable to save Component (tcm:33-32599).
    ]]><tcm:Token>RESID_4574</tcm:Token>
        <tcm:Token>RESID_4418</tcm:Token>
        <tcm:Token>tcm:33-32599</tcm:Token>
    </tcm:Line>
    <tcm:Line ErrorCode="80040345" Cause="true" MessageID="15747"><![CDATA[ 

    Unexpected element: MultimediaFileSize
    ]]><tcm:Token>MultimediaFileSize</tcm:Token>
    </tcm:Line>
    <tcm:Details>
        <tcm:CallStack>
            <tcm:Location>ComponentBL.CheckMultiMediaProperties</tcm:Location>
            <tcm:Location>ComponentBL.CheckMultiMediaProperties</tcm:Location>
            <tcm:Location>ComponentBL.Update</tcm:Location>
            <tcm:Location>XMLState.Save</tcm:Location>
            <tcm:Location>Component.Save</tcm:Location>
        </tcm:CallStack>
    </tcm:Details>
</tcm:Error>

Can you please let me know what am I doing wrong here?

Upvotes: 4

Views: 512

Answers (4)

user1373140
user1373140

Reputation: 489

Thanks for your responses. I was deleting the node but at the wrong place. I update the code like this and it works fine now.

 if (localComponent.IsMultimediaComponent)

                        {

                            XmlNode multimediaFileSizeNode = localComponentXML.SelectSingleNode("//*[local-name()='MultimediaFileSize']",tridionNamespace);

                            XmlNode dataNode = multimediaFileSizeNode.ParentNode;

                            dataNode.RemoveChild(multimediaFileSizeNode);

                        }



                        localComponent.UpdateXML(localComponentXML.InnerXml);

Upvotes: 3

Siva Charan
Siva Charan

Reputation: 18064

I usually do this way:-

mComponent = (Component)mTDSE.GetObject("YOUR-COMPONENT-ID", EnumOpenMode.OpenModeView, null, XMLReadFilter.XMLReadAll);
mComponent.CheckOut(false);
mComponent.MetadataFields["YOUR-METADATA-FIELD-NAME"].value[1] = "VALUE TO BE REPLACED";
mComponent.Save(true);

Upvotes: 1

Chris Summers
Chris Summers

Reputation: 10163

When you do this you need to only save the modified metadata data (not the entire XML). Try removing all of the child nodes except tcm:Metadata from the XML structure before calling .UpdateXML()

Perhaps you could paste your sample XML if you need further assistance.

Upvotes: 2

Nuno Linhares
Nuno Linhares

Reputation: 10234

Include only the tcm:Metadata node in your update?

Specifically, it is complaining about you specifying the size of the mm file, which you shouldn't, that's a system property. Clean up the XML you receive from Tridion to remove that property (it might then complain about another property, just do what it asks you to).

EDIT: Reading the error messages is a great skill to have...

Upvotes: 2

Related Questions