4

I am getting "The given path's format is not supported." when I am just trying to download multimedia image from my SDL Tridion 2011 SP1, below is the path I am getting, no idea how "N:" etc are coming.

D:\delete\Images\N:\dmc.FlipMedia.Clients.TestCMS\2009_WorkInProgress\creatives\05_May\Kids under 16 go free to UK\assets_graphics\jpg\Kids_go_free_385x306.jpg

Below is the code:

 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();
        } 

Please suggest!!

Edit:

I got filename using Nuno Suggestions, however moving forward to

 Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcm);

I am getting below error, any suggestion on this?

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" '.
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198
  • Check here http://stackoverflow.com/questions/5823006/wcf-server-error-the-content-type-text-html-of-the-response-message-does-not-ma and here http://stackoverflow.com/questions/5263150/the-content-type-text-html-charset-utf-8-of-the-response-message-does-not-match – Nuno Linhares Dec 19 '12 at 13:27

2 Answers2

5

As you probably figured out by now, string file = "D:\\delete\\Images\\" + multimediaComponent.BinaryContent.Filename;will append full file name (including path) and therefore generate a wrong path.

Try using something like string file = "D:\\delete\\Images\\" + Path.GetFilename(multimediaComponent.BinaryContent.Filename);

Nuno Linhares
  • 10,214
  • 1
  • 22
  • 42
  • 2
    Indeed. I'd also suggest using @ before the quotes so you don't have to use double backslashes and using Path.Combine instead of string concatenation. For example: `string file = Path.Combine(@"D:\delete\Images", Path.GetFilename(multimediaComponent.BinaryContent.Filename));` – Peter Kjaer Dec 19 '12 at 12:12
  • @Nuno...thanks I got filename using above code any idea why I am getting error added in question – Manoj Singh Dec 19 '12 at 12:26
0

Do this way:-

Stream tempStream = streamDownloadClient.DownloadBinaryContent(tcmId);
MemoryStream memoryStream = new MemoryStream();
int b;
do
{
    b = tempStream.ReadByte();
    memoryStream.WriteByte((byte)b);
} while (b != -1);

binaryContent = memoryStream.ToArray();​
Siva Charan
  • 17,940
  • 9
  • 60
  • 95