I have a folder created in my Project. In my code I want to determine if a file exists in that folder. How can I do that ?
---------- EDIT:
I'll try to put the question in a different way.
I have an mvc 4 project that has all of the startup folders : Controllers, Views, Models etc. I have added another folder in my project called MyResources
. In that folder I have added few pdf files. In one of my controllers i have a logics that has to check if the passed name of file exists in that particular folder. Lets say that I have passed PassedFileName.pd
and I want to check if that file is available in the MyResources
folder. I have tried with the System.IO.File.Exists(@"~/MyResources/PassedFileName.pdf")
but it always returns false
.
When I right-click on the file itself( in the solution explorer) and see what is its actual path it says: C:\(phisical-path-on-my-machine)\MyProjectName\Resources\ReturnHelpPdf.pdf
. That makes me think that I need the path to my project somehow so I can string.Format
it. I hope that you understand what are my concerns. I know how to check if file exists on the File system. But here I have to make check for something I am not complete sure if I have the full information about.
You can use
var fileExists = File.Exists(path);
to check if a file exists at a given path if the file exists, the variablefileExists
will betrue
else it isfalse
.Of course you can also check directly in a if statement