Display SVG Files

2 posts, 0 answers
  1. Purchasing
    Purchasing avatar
    1 posts
    Member since:
    Oct 2011

    Posted 13 Nov 2013 Link to this post


    We want to display an SVG File as Byte-Array on the RadBinaryImage Control.

    If we set the ImageUrl directly in the html code, it works fine.
    <telerik:RadBinaryImage ID="RadBinaryImage1" ImageUrl="~/Pictures/10039818.svg" runat="server" />

    But,if we put the SVG Byte[] into the DataValue in the C# code, we get an exception.
    private void LoadPicture()
     byte[] bytes = File.ReadAllBytes("C:\\Projects\\TelerikTest\\TelerikTest\\Pictures\\10039818.svg");
     RadBinaryImage2.DataValue = bytes;

    Please see the execption attached(capture3.png).

    How can we use the RadBinaryImage with SVG Byte Array in C#?

  2. Vasil
    Vasil avatar
    1604 posts

    Posted 14 Nov 2013 Link to this post

    Hi Peter,

    When you set the image as ImageUrl, the RadBinaryImage only resolve the path to the image, and it is directly shown in your browser.

    When you bind the data, the image is hosted and then shown in the browser. There are several reasons for this not to work:
    1. You don't have to call the DataBind, just assign the DataValue. Because DataBind will bind the control from it's parent, and it could even set new DataValue when binding, and clears yours.
    2. The required HTTP handlers are missing from your web config. Check this help topic to see how to add them: http://www.telerik.com/help/aspnet-ajax/binaryimage.html
    3. The data in the file is corrupted, incomplete or not in correct format.

    To confirm that 3 is not the problem, you could read the files as Image:
    And then convert the image back to byte and set it to the RadBinaryImage.
    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    Image YourImage = Image.FromFile (your_file_name,true);
    YourImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
    image.DataValue = stream.ToArray();
    You could debug the lines above after adding it in your page and see if the image is correct.

    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top