Reputation: 105
I'm trying to save image in a folder using relative path. My code is
bmp1.Save(@"~/mintemp/" + filename, jgpEncoder, myEncoderParameters);
I'm getting error like this.
A generic error occurred in GDI+
But when i change path like below
bmp1.Save(@"E:\web data\website\mintemp\" + filename, jgpEncoder, myEncoderParameters);
Code working fine in absolute path. Can anyone help me to solve out this issue becaue i want to save using relative path. Thanks in advance, sorry for my bad English.
Upvotes: 2
Views: 2915
Reputation: 17953
Try using Server.MapPath
. The MapPath
method maps the specified relative or virtual path to the corresponding physical directory on the server.
Note that, Server.MapPath(@"~/mintemp/")
returns the physical path of the folder mintemp
present in the root directory of the application
bmp1.Save(Server.MapPath(@"~/mintemp/") + filename, jgpEncoder, myEncoderParameters);
Upvotes: 1
Reputation: 610
You can use Server.MapPath
function to get the relative path.
In your case it'll be : Server.MapPath("E:\web data\website\mintemp\" + filename)
. It return a string that you can use in your Save
method.
More explanations here : https://forums.asp.net/t/1813648.aspx?Any+difference+between+Server+MapPath+and+Server+MapPath+
Upvotes: 1