G
GiJeet
Every example I see regarding opening a file uses paths like this:
FileStream inputStream = new FileStream ("C:\\file.txt",
FileMode.Open, FileAccess.Read);
Great if the file is always on the root of the C: drive but what if
that’s not the case?!
If I add a file to a project in my solution I can’t hard code the path
to the file which lives in something like C:\Documents and Settings
\Administrator\My Documents\Visual Studio 2005\Projects….
So how do I access a file using relative paths from the solution? And
if I have a program in one project trys to open a file in another
project how is this accomplished?
For example, I have two projects in my solution A & B. I have a
project reference in A to B. In B I have added an xml file to the
project. It’s in the root of the project. B has a class, BClass that
has a static function that needs to open that file. I call this
function in B from A, eg: BClass.OpenFile(). The file is physically
located in something like C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2005\Projects (which will not exist on the
server this solution gets deployed to) and when A runs it’s the
currently executing program so any Application path will refer to A
not B but the file is in B. How to access that file?
TIA
G
FileStream inputStream = new FileStream ("C:\\file.txt",
FileMode.Open, FileAccess.Read);
Great if the file is always on the root of the C: drive but what if
that’s not the case?!
If I add a file to a project in my solution I can’t hard code the path
to the file which lives in something like C:\Documents and Settings
\Administrator\My Documents\Visual Studio 2005\Projects….
So how do I access a file using relative paths from the solution? And
if I have a program in one project trys to open a file in another
project how is this accomplished?
For example, I have two projects in my solution A & B. I have a
project reference in A to B. In B I have added an xml file to the
project. It’s in the root of the project. B has a class, BClass that
has a static function that needs to open that file. I call this
function in B from A, eg: BClass.OpenFile(). The file is physically
located in something like C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2005\Projects (which will not exist on the
server this solution gets deployed to) and when A runs it’s the
currently executing program so any Application path will refer to A
not B but the file is in B. How to access that file?
TIA
G