0

I have written a simple application in C# it uses an XML file. When the program loads it must take values from the file and load them into an arraylist, The problem is when I move the program into a different PC I must change the file location manually. How can I make the file name not to change even when running the program in a different PC.

3
  • 1
    What file location are you talking about? Where do you need to change it manually? Commented Sep 11, 2012 at 13:46
  • sounds like you just need to pass a filename as parameter to the application -> stackoverflow.com/questions/653563/… Commented Sep 11, 2012 at 13:47
  • Why do you have to change the file name? You need to explain more about how you install your program on other machines, and also where the Xml file is supposed to be relative to your program. Commented Sep 11, 2012 at 14:01

3 Answers 3

2

Copy theXML file in the same folder or subdfolder of where the program is so it can allways be found using for example:

Path.GetDirectoryName(Application.ExecutablePath);
Sign up to request clarification or add additional context in comments.

Comments

1

There are a few ways to solve this. One is to pass the file name on as a command line argument. For example:

public static void main(string[] args)
{
    // Use the first argument on the command line
    string file = args[0];
}

Another is to include it in the app.config file. See https://codereview.stackexchange.com/questions/186/getting-setting-default-values-from-my-app-config for a good example.

Comments

1

You can store the file inside the assembly location or some common location

string myfile = System.IO.Path.Combine(Assembly.GetExecutingAssembly().Location,"your file name");

1 Comment

I think this is the best answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.