Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am using asp.net,vs2008,c#.net.
I want to fetch file from root directory using asp.net.

i am using this typr of code.......
C#
string file = Server.MapPath("App_Data" + filename);

help will be appreciated.....

thanks
Posted
Updated 31-Dec-11 3:05am
v2

use Server.MapPath to obtain the physical path of a particular directory
//Physical path of the root directory
        Server.MapPath("/")

Server.MapPath is indifferent on whether you use backslashes (\) or forward slashes (/).
For more reference :- Using Server.MapPath [^]
 
Share this answer
 
v2
Comments
Espen Harlinn 31-Dec-11 9:09am    
5'ed!
RaviRanjanKr 31-Dec-11 9:32am    
Thanks :)
Try:
C#
string file = Server.MapPath("~/App_Data" + filename);

or
C#
string file = Server.MapPath("/App_Data" + filename);

And make sure filename starts with a '/' or '\' as well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900