Search This Blog

August 8, 2007

Adding a Resource File Is So Good!

If you need to create an xml file or a text file in your project, you might want to use it all the time. How can you know its complete path? Is it in C drive or D drive? Do you need to hardcode the path? Probably not!

The simple idea is that we can create a new resource file, and add a text file or an xml file in it. When we run the program, the file will be under the folder of bin\debug. Later we can use C# function to get the complete file path and load the data as follows:

string CurrentDirectory = Directory.GetCurrentDirectory();

string resourceFilePath = CurrentDirectory + @"\" + "test.xml";

Is it a piece of cake?

No comments: