How can I import external files into SDL Tridion 2011 using core service?

孤者浪人 提交于 2019-12-04 03:05:51

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.

The process for uploading binaries into Tridion using the Core Service is:

  1. Upload the binary data to the Tridion server using a StreamUploadClient. This returns you the path of the file on the Tridion server.
  2. Create a BinaryContentData that points to the file on the Tridion server (so with the path you got back from step 1)
  3. Create a ComponentData that refers to the the BinaryContentData from step 2
  4. Save the ComponentData

You are setting the local path for your file in step 2.

binaryContent.UploadFromFile = @"C:\Documents and Settings\My Poc\images.jpg";

But Tridion will never be able to find that file there. You instead should set the path that you got back from UploadBinaryContent:

string tempLocation;
using (StreamUploadClient streamClient = new StreamUploadClient())
{
  FileStream objfilestream = new FileStream(@"\My Documents\My Poc\images.jpg",
                                            FileMode.Open, FileAccess.Read);
  tempLocation = streamClient.UploadBinaryContent("images.jpg", objfilestream);
}
BinaryContentData binaryContent = new BinaryContentData();
binaryContent.UploadFromFile = tempLocation;

Note that the Ryan's original code does exactly that.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!