尝试从Tridion 2011 SP1下载多媒体图像时不支持获取文件路径
我得到的是“给定路径的格式不受支持”。当我试图从SDL Tridion 2011 SP1下载多媒体图像时,下面是我得到的路径,不知道“N:”等是如何出现的 D:\delete\Images\N:\dmc.FlipMedia.Clients.TestCMS\2009\u WorkInProgress\creatives\05\u May\16岁以下儿童免费进入英国\assets\u graphics\jpg\Kids\u go\u free\u 385x306.jpg 下面是代码:尝试从Tridion 2011 SP1下载多媒体图像时不支持获取文件路径,tridion,tridion-2011,Tridion,Tridion 2011,我得到的是“给定路径的格式不受支持”。当我试图从SDL Tridion 2011 SP1下载多媒体图像时,下面是我得到的路径,不知道“N:”等是如何出现的 D:\delete\Images\N:\dmc.FlipMedia.Clients.TestCMS\2009\u WorkInProgress\creatives\05\u May\16岁以下儿童免费进入英国\assets\u graphics\jpg\Kids\u go\u free\u 385x306.jpg 下面是代码: public
public static void GetBinaryFromMultimediaComponent(字符串tcm、CoreServiceClient客户端、StreamDownloadServiceClient streamDownloadClient)
{
ComponentData multimediaComponent=client.ReadItem(tcm)作为ComponentData;
//生成您自己的文件名和文件位置
string file=“D:\\delete\\Images\\”+multimediaComponent.BinaryContent.Filename;//这里我得到了上面的路径
//从Tridion中写出现有文件
FileStream fs=File.Create(File);//这里获取异常
字节[]二进制内容=null;
如果(multimediaComponent.BinaryContent.FileSize!=-1)
{
Stream tempStream=streamDownloadClient.DownloadBinaryContent(tcm);
var memoryStream=新的memoryStream();
tempStream.CopyTo(memoryStream);
binaryContent=memoryStream.ToArray();
}
Write(binaryContent,0,binaryContent.Length);
fs.Close();
}
请建议
编辑:
我使用Nuno建议得到了文件名,不过我继续
Stream tempStream=streamDownloadClient.DownloadBinaryContent(tcm);
我得到下面的错误,有什么建议吗
The content type multipart/related; type="application/xop+xml";start="";boundary="uuid:5f66d04b-76d3-4d3a-b8e3-b7b91e00ed32+id=2";start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 595 bytes of the response were: ' --uuid:5f66d04b-76d3-4d3a-b8e3-b7b91e00ed32+id=2 Content-ID: Content-Transfer-Encoding: 8bit Content-Type: application/xop+xml;charset=utf-8;type="text/xml" '.
正如您现在可能已经了解的那样,
string file=“D:\\delete\\Images\\”+multimediaComponent.BinaryContent.Filename代码>将附加完整的文件名(包括路径),因此生成错误的路径
尝试使用类似于string file=“D:\\delete\\Images\\”+Path.GetFilename(multimediaComponent.BinaryContent.Filename)的方法代码>请按以下方式执行:-
Stream tempStream=streamDownloadClient.DownloadBinaryContent(tcmId);
MemoryStream MemoryStream=新的MemoryStream();
int b;
做
{
b=tempStream.ReadByte();
memoryStream.WriteByte((字节)b);
}而(b!=-1);
binaryContent=memoryStream.ToArray();
的确如此。我还建议在引号之前使用@,这样就不必使用双反斜杠,也不必使用Path.Combine而不是字符串连接。例如:string file=Path.Combine(@“D:\delete\Images”,Path.GetFilename(multimediaComponent.BinaryContent.Filename))代码>@Nuno…谢谢我用上面的代码得到了文件名。知道我为什么在问题检查中添加了错误吗?这里是相同的代码,可能存在访问问题。我明天早上需要检查一下,做一些必要的事情。