-1

File is exists in ~/NewsPictures/ my code returns always false. I want to delete a file that exists in location ~/NewsPictures/1.png by name

 My code: 
bool t = false;
        String Location = "~/NewsPictures/1.png";
        if (File.Exists(Location) == true)
        {
            t = true;
        }

What I am doing wrong.

Sidra Kanwal
  • 115
  • 9

1 Answers1

1

As Marvin Smit said, System.IO.File.Exists does not recognise '~' in the same way that System.Web.UI.WebControls.FileUpload does.

And as CodeCaster said, you need to get Server.MapPath() to bridge that gap. See Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference? for more details (and examples) of that.

Community
  • 1
  • 1
ClickRick
  • 1,525
  • 2
  • 15
  • 35