c# WCF Server application - access to a file on the server relatively
I have a c# server application (WCF) and I have a file saved on that server and i want to access it relatively so every dev machine can work with it.
this is the file path.
C:\Users\ben\Documents\Visual Studio 2010\Projects\ myfile.xml
the project where i want to access the file from is in:
C:\Users\ben\Documents\Visual S开发者_Go百科tudio 2010\Projects\ MyProject
what is the best way to access the myfile.xml (relatively)? from MyProject?
Well, when you run the project, your current directory will be something like:
C:\Users\ben\Documents\Visual Studio 2010\Projects\MyProject\MyProject\bin\Debug\
So you will probably want to do something else.
Include the file in the project and go to File Properties for the file. Select Copy Always
for the Copy to Output Directory
setting. The file will then be copied to the same directory as the EXE when compiling/building. That way you can access the file simply by its filename.
From your question , what is under stood is that you want to access your project location , without the executable file and folder . To do that try the following code :
string AppPath = System.Environment.CommandLine;
int pos = AppPath.IndexOf("bin");
AppPath = AppPath.Remove(pos);
AppPath += "myfile.xml";
精彩评论