尝试从Tridion 2011 SP1下载多媒体图像时不支持获取文件路径

Man*_*ngh 4 tridion tridion-2011

我得到"不支持给定路径的格式." 当我只是尝试从我的SDL Tridion 2011 SP1下载多媒体图像时,下面是我得到的路径,不知道"N:"等即将到来.

D:\ delete\Images\N:\ dmc.FlipMedia.Clients.TestCMS\2009_WorkInProgress\creatives\05_May\16岁以下儿童免费访问英国\ assets_graphics\jpg\Kids_go_free_385x306.jpg

以下是代码:

 public static void GetBinaryFromMultimediaComponent(string tcm, CoreServiceClient client, StreamDownloadServiceClient streamDownloadClient)
        {           

            ComponentData multimediaComponent = client.ReadItem(tcm) as ComponentData;

            // Generate you own file name, and file location
            string file = "D:\\delete\\Images\\" + multimediaComponent.BinaryContent.Filename;//Here I am getting above path

            // Write out the existing file from Tridion
            FileStream fs = File.Create(file);//Here getting the exception
            byte[] binaryContent = null;

            if (multimediaComponent.BinaryContent.FileSize != -1)
            {
                Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcm);
                var memoryStream = new MemoryStream();
                tempStream.CopyTo(memoryStream);
                binaryContent = memoryStream.ToArray();
            }

            fs.Write(binaryContent, 0, binaryContent.Length);
            fs.Close();
        } 
Run Code Online (Sandbox Code Playgroud)

请建议!!

编辑:

我使用Nuno建议获得了文件名,但是继续前进

 Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcm);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误,对此有任何建议吗?

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" '.
Run Code Online (Sandbox Code Playgroud)

Nun*_*res 5

正如您现在可能已经想到的那样,string file = "D:\\delete\\Images\\" + multimediaComponent.BinaryContent.Filename;将追加完整的文件名(包括路径),从而生成错误的路径.

尝试使用类似的东西 string file = "D:\\delete\\Images\\" + Path.GetFilename(multimediaComponent.BinaryContent.Filename);

  • 确实.我还建议在引号之前使用@,这样你就不必使用双反斜杠并使用Path.Combine而不是字符串连接.例如:`string file = Path.Combine(@"D:\ delete\Images",Path.GetFilename(multimediaComponent.BinaryContent.Filename));` (2认同)