如何使用核心服务将外部文件导入 SDL Tridion 2011?

2024-04-27

我想使用核心服务将 PDF、Word 和 Excel 文件推送到 SDL Tridion 2011。

我尝试了下面的代码但收到此错误:

属性“BinaryContent”的值无效。无法打开上传的文件:

using (ChannelFactory<ISessionAwareCoreService> factory =
    new ChannelFactory<ISessionAwareCoreService>("wsHttp_2011"))
{
  ISessionAwareCoreService client = factory.CreateChannel();
  ComponentData multimediaComponent = (ComponentData)client.GetDefaultData(
                                       ItemType.Component, "tcm:19-483-2");
  multimediaComponent.Title = "MultimediaFile";

  multimediaComponent.ComponentType = ComponentType.Multimedia;
  multimediaComponent.Schema.IdRef = "tcm:19-2327-8";

  using (StreamUploadClient streamClient = new StreamUploadClient())
  {
    FileStream objfilestream = new FileStream(@"\My Documents\My Poc\images.jpg",
                                              FileMode.Open, FileAccess.Read);
    string tempLocation = streamClient.UploadBinaryContent("images.jpg",
                                                           objfilestream);
  }
  BinaryContentData binaryContent = new BinaryContentData();
  binaryContent.UploadFromFile = @"C:\Documents and Settings\My Poc\images.jpg";
  binaryContent.Filename = "images.jpg";
  binaryContent.MultimediaType = new LinkToMultimediaTypeData()
  {
    IdRef ="tcm:0-2-65544"
  };
  multimediaComponent.BinaryContent = binaryContent;

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

  client.CheckIn(savedComponent.Id, null);
  Response.Write(savedComponent.Id);
}    

在这里阅读 Ryan 的精彩文章http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011 http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011

所有二进制文件都以相同的方式处理 - 因此他的图像技术对于文档同样有效,只需确保您使用具有适当 mime 类型的架构即可。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用核心服务将外部文件导入 SDL Tridion 2011? 的相关文章

随机推荐