0

I want to use a path set in my system variable to read/write data to.

System variable is called "LUCTEST" and has value "C:\Users\Luc" XML is in C:/Users/Luc/test.xml

My code does read the XML OK, but how does it know to choose the test.xml?? Can I specify exactly what the xml should be called if there are multiple in "C:\Users\Luc"

Below is my current code:

   private void Form1_Load(object sender, EventArgs e)
    {
        string path = Environment.GetEnvironmentVariable("LUCTEST",EnvironmentVariableTarget.Machine);
        if (File.Exists(path))
            App.Phonebook.ReadXml(path);
        phonebookBindingSource.DataSource = App.Phonebook;
        panel1.Enabled = false;
    }
Luc
  • 13
  • 3
  • Yes, you definitely can do so. You just need to replace hardcoded path with reading the value of environmental variable of your choice. https://learn.microsoft.com/pl-pl/dotnet/api/system.environment?view=netframework-4.8 – quetzalcoatl Jan 23 '20 at 01:36
  • 2
    Are you looking for [How do I get and set Environment variables in C#?](https://stackoverflow.com/q/185208/3744182) and [What is the best way to combine a path and a filename in C#/.NET?](https://stackoverflow.com/q/1048129/3744182)? – dbc Jan 23 '20 at 01:37
  • Neither of your calls to `System.Format` do anything. You need to read the documentation on how it works. It's not what you're looking for anyway - you want `Path.Combine`. – Ken White Jan 23 '20 at 01:43

0 Answers0