I made a program in C# and was using a hardcoded reference to the Program Files directory whilst making the program. I'd now like to remove the hardcoded reference.
I have been recommended this method from Eric on stackoverflow in a recent topic. However, I wasn't able to understand how to run the code from a button_click:
Eric said:
string programFilesFolder =
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
Continuing that example you could do something like this
string pathToFile =
Path.Combine(programFilesFolder, @"TEST\ok.txt");
if (File.Exists(pathToFile))
File.Delete(pathToFile);
To be 100% honest with you all, I am newish to c# and am still learning...
Can someone please give an example on how to invoke the code above from a button_click? I am going to be doing this to more than one file using the same button.
I did ask this question in a comment on the other thread, but I think they all moved on.
Path.Combine(programFilesFolder, @"TEST\ok.txt")where you hard coded the path before?