Difference between Server.mappath and Page.resolveURL

S

SandyIsCool

Hi,

Can any one let me know what is difference between Server.mappath and
Page.resolveURL and what are the situations we use them.

Thanks,
Sandy
 
M

Mark Fitzpatrick

The ResolveUrl method is designed to create a friendly URL for a given
resource. For example, when you have a control that references an image,
you'll want the image to be referenced correctly when that control is placed
within a page. The ResolveUrl will create the url in a friendly way that is
relative to the page instead of relative to the control.

The Server.MapPath is used to find the file system path for a given
resource. For example: Server.MapPath("web.config") may give something like
c:\inetpub\wwwroot\web.config. It's used when you're trying to work with
files from the server's file system, such as saving uploaded files, creating
files on the server, referencing file-based databases.
 
S

SandyIsCool

Hi
Mark.

I used the below code for an image button

image1.imageurl="~/images/image1.jpg";
image1.imageurl=Page.ResolveUrl("~/images/image1.jpg");

Both statements work fine..
I want to see a case where resolveURL method makes a difference.
Thanks,
Sandeep
 
E

Edwin Knoppert

I often use plain html controls, not asp.net controls.
so an IMG can not understand the virual root tilde (~) and therefore
resoulveurl() will help

< IMG SRC='<%= ResolveURL(.... etc..

Also!! .. i use it to redirect and always use the root with subfolders for
redirect.
Unless the page is in the same folder.
I don't like to use ..\folder\page.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,087
Latest member
JeremyMedl

Latest Threads

Top