How to get virtual path of a folder on a server independent of where it is reside.

G

gujarsachin2001

Hello friends,

I have one folder Named as MainFolder on server. I have one more
folder named as subfolder inside tht main folder.Now I want to save
some pictures in tht folder but at runtime I m not getting correct
virtual path of tht folder. As Server.MapPath() & MapPath methods
returns physical path.So How I can Access tht folder independent of
where my application is insatlled.
I have used following metthods but it doesnt work,

Server.MapPath(".//subfolder");
MapPath("~/subfolder");
Request.MapPath(".//subfolder");

Thxxxxxxx,
Sachin.
 
D

Dave Sexton

Hi Sachin,

You can create a virtual path by simply concatenating strings that represent
the known paths:

string root = "~/";
string basePath = "folder/";
string filePath = "subfolder/file.ext";

string path = root + basePath + filePath;

This produces a virtual path that is independent of the physical location of
your application:

~/folder/subfolder/file.ext

If I don't exactly understand your question they you can try rephrasing it
and providing more detail. You may want to take a look at this as well:

VirtualPathUtility Class
http://msdn2.microsoft.com/en-us/library/system.web.virtualpathutility.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

Top