在Tridion Templating类中创建多媒体组件

时间:2013-01-12 10:16:04

标签: tridion

我正在尝试使用以下代码在Tridion模板类中创建多媒体组件。

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);

请注意,“tcm:21-2008-2”是必须创建组件的文件夹TCM ID。 “tcm:10-6532-8”是多媒体模式ID,“tcm:0-36-65544”是多媒体类型ID。

然而,似乎存在一些问题,并且失败并出现以下错误:

  

指向Schema的链接值无效。      在Tridion.ContentManager.Utilities.ThrowInvalidLinkException(链接链接,KernelException innerException)      在Tridion.ContentManager.IdentifiableObject.AssertValidLink(链接链接)      在Tridion.ContentManager.IdentifiableObject.AssertValidLinks(IEnumerable`1链接)      在Tridion.ContentManager.IdentifiableObject.AssertValidLinks()      在Tridion.ContentManager.IdentifiableObject.OnSaving(SaveEventArgs eventArgs)      在Tridion.ContentManager.ContentManagement.RepositoryLocalObject.OnSaving(SaveEventArgs eventArgs)      在Tridion.ContentManager.ContentManagement.VersionedItem.OnSaving(SaveEventArgs eventArgs)      在Tridion.ContentManager.ContentManagement.Component.OnSaving(SaveEventArgs eventArgs)      在Tridion.ContentManager.IdentifiableObject.Save(SaveEventArgs eventArgs)      在Tridion.ContentManager.ContentManagement.VersionedItem.Save(Boolean checkInAfterSave)      在Tridion.ContentManager.ContentManagement.VersionedItem.Save()

以上错误发生在下面的语句xmlMultimediaComponent.Save()

任何想法我们如何将LinkToMultimedia类型模式ID传递给多媒体组件?

1 个答案:

答案 0 :(得分:11)

我认为架构ID必须包含上下文发布ID,所以在这种情况下10-6532-8应该是21-6532-8。

由于