如何使用核心服务将外部文件导入 SDL Tridion 2011? [英] How can I import external files into SDL Tridion 2011 using core service?
问题描述
我想使用核心服务将 PDF、Word 和 Excel 文件推送到 SDL Tridion 2011.
我尝试了以下代码,但出现此错误:
<块引用>属性BinaryContent"的值无效.无法打开上传的文件:
using (ChannelFactory factory =new ChannelFactory("wsHttp_2011")){ISessionAwareCoreService 客户端 = factory.CreateChannel();ComponentData 多媒体组件 = (ComponentData)client.GetDefaultData(ItemType.Component, "tcm:19-483-2");多媒体组件.Title = "多媒体文件";多媒体组件.组件类型 = 组件类型.多媒体;多媒体组件.Schema.IdRef = "tcm:19-2327-8";使用 (StreamUploadClient streamClient = new StreamUploadClient()){FileStream objfilestream = new FileStream(@"\My Documents\My Poc\images.jpg",FileMode.Open, FileAccess.Read);string tempLocation = streamClient.UploadBinaryContent("images.jpg",对象文件流);}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"};多媒体组件.BinaryContent = binaryContent;IdentifiableObjectData savedComponent = client.Save(multimediaComponent,新的读取选项());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>
所有二进制文件都以相同的方式处理 - 因此他的图像技术对文档同样有效,只需确保使用具有适当 mime 类型的架构即可.
I want to push PDF, Word and Excel files into SDL Tridion 2011 by using core service.
I tried below code but get this error:
Invalid value for property 'BinaryContent'. Unable to open uploaded file:
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);
}
Have a read of Ryan's excellent article here http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011
All binary files are handled the same way - so his technique for images will be equally as valid for documents, just make sure you use a Schema with the appropriate mime types.
这篇关于如何使用核心服务将外部文件导入 SDL Tridion 2011?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!