Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi , i have below code :

C#
string filename = "L:/chikardarin Website/WebApplication2/image_Logo/" + ImgName;
if (System.IO.File.Exists(filename))
{
    System.IO.File.Delete(filename);
    Response.Write("Deleted");
}


i would like to add inster of L:/chikardarin Website/WebApplication2/image_Logo/
my direct location which is ../../image_Logo

but it wont do any action . please help me how to write it from my web root .

thanks .
Posted

To get web root you use Server.MapPath and give it the virtual path.

C#
String path = Server.MapPath("~/image_logo/ImageName.gif");


will return L:\chikardarin WebSite\WebApplication2\image_Logo\ImageName.gif assuming that WebApplication2 is your root.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Oct-14 17:43pm    
Sure, a 5.
—SA
C#
string filename = Server.MapPath("~/image_logo/" + ImgName);
if (System.IO.File.Exists(filename))
{
    System.IO.File.Delete(filename);
    Response.Write("Deleted");
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Oct-14 17:43pm    
Sure, a 5.
—SA

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