2

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.

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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+

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.