Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I'm using that code below to get the text from a hidden file that contains the string of an SVG tag in the ASPX file

then I used the SVG library to get a bitmap image out of this SVG text
the function Draw() returned a bitmap image just fine but whenever I try to save that bitmap I get the error stated above
any idea what might be the problem is??
I set the temp folder permissions to full control for everyone and as you can see I'm sure that the stream is still open while I try to save the file

C#
string svgText = HttpUtility.UrlDecode(svgHolder.Value, System.Text.Encoding.Default);
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(svgText)))
{
    var svg = SvgDocument.Open<SvgDocument>(stream);
    Bitmap image = svg.Draw();
    image.Save("~/img/temp/temp.bmp");
}
Posted
Comments
Matt T Heffron 28-Sep-15 20:22pm    
Wrap the image.Save() in a try/catch and look at the exception in the debugger for any additional information that may be there... (E.g., is it a System.Runtime.InteropServices.ExtenalException ? That has an Hresult property that could provide additional info.)

1 solution

There are loads of ways to cause this, but in your case, it's almost certainly becais ethe path is invalid: Bitmap.Save expects a "normal" windows path, not an IIS based path descriptor.

Try this:
C#
image.Save(Server.MapPath("~/img/temp/temp.bmp"));
And make sure that the "img" and "temp" folders do exist.

In the longer term, web based code should never refer to "fixed" file names, as they are inherently running in multiuser environments. There is a very good chance that the next user will immediately overwrite your file!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900