The C# program I am writing needs to access a few XML files and a txt log file, stored in an external folder. What I wanted to do was to drop these files in a folder called ConfigFiles, and then just drop that ConfigFiles folder into the Visual Studio project folder, so that no matter what computer I run the program from, it will be able to access the files. I have not gotten the relative path to work yet. How should I set this up?
I tried:
//1)Make sure config folder exist and start application Logging
if (!Directory.Exists(FFXIVFolderPath))
{
var appRoot = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var fullPath = Path.Combine(appRoot, FFXIVFolderPath);
var message = "FFXIV config directory (" + fullPath + ") does not exist, please select new folder...";
Globals.Instance.ShowMessage(message);
// Show the FolderBrowserDialog
var folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
FFXIVFolderPath = folderBrowserDialog1.SelectedPath;
}
else {Application.Exit();}
MemoryApi.SetForegroundWindow(Handle);
}
UPDATE (MY SOLUTION): I ended up deciding that I wanted my resource files to be in the "special folder" Documents, under the current user (the users should be able to modify them). This is my code in case someone needs to do the same:
private const string FFXIVFolder = @"My Games\XYZ Game\Bot Config Files";
public static string FFXIVFolderPath { get; private set; }
private void MainForm_Load() {
//1)Make sure config folder exist and start application Logging
string documentsDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
FFXIVFolderPath = Path.Combine(documentsDir, FFXIVFolder);
if (!Directory.Exists(FFXIVFolderPath))
{
var message = "FFXIV config directory (" + FFXIVFolderPath + ") does not exist, please select new folder...";
Globals.Instance.ShowMessage(message);
// Show the FolderBrowserDialog
var folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
FFXIVFolderPath = folderBrowserDialog1.SelectedPath;
}
else
{
Application.Exit();
return;
}
MemoryApi.SetForegroundWindow(Handle);
}
Globals.Instance.LoggerDictionary.Add("ApplicationLog", new Logger("ApplicationLog"));
}