Reputation: 677
I am using Visual Studio 2010 Professional.
I have created a folder inside a project in my solution using the "right click -> Add -> New folder -> folder1"
method, and now my solution explorer looks like this:
Is there a way for me to programmatically access files inside this folder (ex: sampleFile.xml) from code, other than get the path of the executable and go from there?
Edit: I want to know if there's a more elegant solution provided by VS/C#, I know I can construct the path using the executable path or base directory.
For example, found this here : if I add the file as a resource (Right click on project -> Properties -> Resources -> Add Resource) a "Resource" folder is generated in my solution explorer :
and I can get the content of the file easily like this :
var newFile = Properties.Resources.newFile1;
Is there something similar for other non-resource files in the solution and can I get the path of the files in a similar way?
Upvotes: 2
Views: 4227
Reputation: 43264
Assuming that Test
is your main project, then the file can be accessed via:
AppDomain.CurrentDomain.BaseDirectory + @"\Folder1\SampleFile.xml"
(This assumes that: (a) you want to access it from within Visual Studio, or (b) that whatever install mechanism you use places Folder1
within the start directory of the application.)
Upvotes: 2