Pushpendra Kuntal
Pushpendra Kuntal

Reputation: 6186

how can get image from a relative path

i am working in asp .net mvc3.

i want to get a image which exist in this location in my project G:\projects\CalcoWoms\CalcoWOMS\Content\pictures\calcologo.png

CalcoWOMS is my project name. i want to fetch this calcologo.png in following line please check following line and tell me how should write this following line in correct way.?

iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance("~/calcologo.png");

means in place of ("~/calcologo.png"); what path i should write ?

Upvotes: 4

Views: 6032

Answers (3)

Alex Aza
Alex Aza

Reputation: 78457

You could use MapPath

var physicalPath = Server.MapPath("~/Content/pictures/calcologo.png");

Upvotes: 5

mccow002
mccow002

Reputation: 6914

You could use the HostingEnvironment object along with Path.Combine

Path.Combine(@HostingEnvironment.ApplicationPhysicalPath, "calcologo.png");

Of course, @HostingEnvironment.ApplicationPhysicalPath will only take you to the root of your application, so you might need to use "Content/picturescalcologo.png".

Upvotes: 0

SBSTP
SBSTP

Reputation: 3639

You could try "%~dp0calcologo.png".
%~dp0 means current directory.

Upvotes: 0

Related Questions