C# Adding folder to project and accessing it??
-
giovedì 26 aprile 2012 02:09
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....
Tutte le risposte
-
giovedì 26 aprile 2012 04:54
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?
- Modificato CountryStyle giovedì 26 aprile 2012 05:00
-
giovedì 26 aprile 2012 16:50
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....
-
giovedì 26 aprile 2012 17:07
See my answer on the other thread you posted on this topic:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/60931fdf-d10b-4653-bb6c-c47a922de664
Dan Randolph
-
giovedì 26 aprile 2012 18:03
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);
-
venerdì 27 aprile 2012 03:02
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???
-
martedì 1 maggio 2012 07:15Moderatore
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 path2 = path.Substring(0, path.LastIndexOf("bin")) + "StoredInfo" + "\\Firstname.txt"; if (File.Exists(path2)) { MessageBox.Show("Worked"); } else MessageBox.Show("Not there");
Have a nice day.Bob Shen [MSFT]
MSDN Community Support | Feedback to us
- Contrassegnato come risposta superlurker martedì 1 maggio 2012 16:26
-
martedì 1 maggio 2012 14:29
OK...the question has changed:
- Proposto come risposta CountryStyle martedì 1 maggio 2012 14:29

