Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, April 26, 2012 2:09 AM
I added a folder to my project " StoredInfo" right above Resources... It has another folder inside "Names" inside names is 2 text docs "Firstname" and "Last" name ..... I need to check to see if the files are there or not, if not create them.....
I can't seem to get the path to show that the folder is there??? It may not be installed in C: so i was trying to find a direct path to the folder???
Please help....
All replies (7)
Tuesday, May 1, 2012 7:15 AM âś…Answered
Hi superlurker,
If "StoredInfo" is a folder added in your project(in Solution Explorer), you can try the sample below.
string path = System.Environment.CurrentDirectory;
string path4 = path.Substring(0, path.LastIndexOf("bin")) + "StoredInfo" + "\\Firstname.txt";
if (File.Exists(path4))
{
MessageBox.Show("Worked");
}
else
MessageBox.Show("Not there");
Have a nice day.
Bob Shen [MSFT]
MSDN Community Support | Feedback to us
Thursday, April 26, 2012 4:54 AM
The main parent directory will be the working directory.
string strWorkingDirectory = Directory.GetCurrentDirectory() will be the location of your exe. Put your folders in this same directory
string fullSubFolderPath = strWorkingDirectory+childDirectoryName
if(Directory.Exists(fullFolderPath)) will tell you if the path exists
Directory.CreateDirectory(fullSubFolderPath) will create a directory.
Does this work for you?
Thursday, April 26, 2012 4:50 PM
I think that is close... I don't need to create a directory ... just if the text.doc if missing from the folder....
where you have (FullFolderPath) is the prob... the project may or maynot be stored in C:
I thought there was a way to just go direct to the added folder in the prodject? like ( I know this is wrong, just to give idea..)
Project1.Properties.Resources.StoredInfo.Names ..... or Project1.StoredInfo.Names ... something like that.. or I'm going about it the wrong way....
Thursday, April 26, 2012 5:07 PM
See my answer on the other thread you posted on this topic:
Dan Randolph
Thursday, April 26, 2012 6:03 PM
Well, if all the default folder locations are not in the program directory you have to know what they are and hard code them. The method Dan had for keeping track of the default directories is standard and good.
You can also just put them in your code (not as good/clean)
I said before to use Directory.GetCurrentDirectory(). That was wrong. Use instead:
string myPath = Path.GetDirectoryName(Application.Executable);
Friday, April 27, 2012 3:02 AM
Maybe this will give you a better idea of what i'm trying to do... It doesnt work ...
string appPath = AppDomain.CurrentDomain.BaseDirectory +"StoredInfo";
string fileName = "Firstname.txt";
string fullPath = Path.Combine(appPath, fileName);
if (File.Exists(fullPath))
{
MessageBox.Show("Worked");
}
else
MessageBox.Show("Not there");
Cant seem to get a relative path to the folder to check if a txt.doc is in there or not????? I have tryed everything???
Tuesday, May 1, 2012 2:29 PM
OK...the question has changed: