Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a multimedia component in Tridion Templating class

Tags:

tridion

I am trying to create a multimedia component in Tridion templating classs with the below code.

MemoryStream stringInMemoryStream = new MemoryStream(ASCIIEncoding.Default.GetBytes("
<test>testing</test>"));                            
Component xmlMultimediaComponent = new Component(engine.GetSession(), new 
  TcmUri("tcm:21-2008-2"));                
xmlMultimediaComponent.Title = "New MM component";
xmlMultimediaComponent.Schema = new Schema(new TcmUri("tcm:10-6532-8"), 
 engine.GetSession());                
xmlMultimediaComponent.BinaryContent.MultimediaType = new MultimediaType(new 
   TcmUri("tcm:0-36-65544"), engine.GetSession());                                         
xmlMultimediaComponent.BinaryContent.MultimediaType.MimeType = "application/xml";
xmlMultimediaComponent.BinaryContent.MultimediaType.FileExtensions = new List<string> 
   {"xml", "XML"};
xmlMultimediaComponent.BinaryContent.UploadFromStream = stringInMemoryStream;
xmlMultimediaComponent.BinaryContent.Filename = "testing.xml".ToLower();                                    
xmlMultimediaComponent.Save();                
xmlMultimediaComponent.CheckIn(true);

Note that "tcm:21-2008-2" is folder TCM ID in which the component has to be created. The "tcm:10-6532-8" is the Multimedia schema ID and "tcm:0-36-65544" is the multimedia type ID.

However there seems to some issue and it is failing with below error:

Link to Schema has invalid value. at Tridion.ContentManager.Utilities.ThrowInvalidLinkException(Link link, KernelException innerException) at Tridion.ContentManager.IdentifiableObject.AssertValidLink(Link link) at Tridion.ContentManager.IdentifiableObject.AssertValidLinks(IEnumerable`1 links) at Tridion.ContentManager.IdentifiableObject.AssertValidLinks() at Tridion.ContentManager.IdentifiableObject.OnSaving(SaveEventArgs eventArgs) at Tridion.ContentManager.ContentManagement.RepositoryLocalObject.OnSaving(SaveEventArgs eventArgs) at Tridion.ContentManager.ContentManagement.VersionedItem.OnSaving(SaveEventArgs eventArgs) at Tridion.ContentManager.ContentManagement.Component.OnSaving(SaveEventArgs eventArgs) at Tridion.ContentManager.IdentifiableObject.Save(SaveEventArgs eventArgs) at Tridion.ContentManager.ContentManagement.VersionedItem.Save(Boolean checkInAfterSave) at Tridion.ContentManager.ContentManagement.VersionedItem.Save()

The above error is occuring at below statement xmlMultimediaComponent.Save().

Any idea how can we pass LinkToMultimedia type schema id to Multimedia component?

like image 901
TempTracer Avatar asked Jan 12 '13 10:01

TempTracer


1 Answers

I think the schema ID must contain the context publication ID, so in this case 10-6532-8 should be 21-6532-8.

Thanks

like image 85
johnwinter Avatar answered Oct 30 '22 23:10

johnwinter