I managed to get OpenSuse up and running with Mono so I could run some tests. I ran the code below with "test1.txt" in application folder and "test2.txt" in a folder called "folder1" under application folder
char sep = Path.DirectorySeparatorChar;
string path1 = Application.StartupPath + "\\test.txt";
string path2 = Path.GetFullPath(path1);
string path3 = Path.Combine(Application.StartupPath, "test.txt");
string path4 = Application.StartupPath + sep + "folder1" + sep + "test2.txt";
richTextBox1.Text = path1 + Environment.NewLine + path2;
richTextBox1.Text += Environment.NewLine + path3 + Environment.NewLine + path4;
richTextBox1.Text += Environment.NewLine + Environment.NewLine;
StreamReader sr = new StreamReader(path3);
string text = sr.ReadToEnd();
sr.Close();
richTextBox1.Text += text;
sr = new StreamReader(path4);
text = sr.ReadToEnd();
sr.Close();
richTextBox1.Text += Environment.NewLine + text;
On Linux, the result was this:
/home/mono/Desktop/PathTest/PathTest/bin/Debug\test.txt
/home/mono/Desktop/PathTest/PathTest/bin/Debug\test.txt
/home/mono/Desktop/PathTest/PathTest/bin/Debug/test.txt
/home/mono/Desktop/PathTest/PathTest/bin/Debug/folder1/test2.txt
This is the text in test1.text
This is the text in test2.text
And on windows, the result was this:
C:\Documents and Settings\Johan\Desktop\PathTest\PathTest\PathTest\bin\Debug\test.txt
C:\Documents and Settings\Johan\Desktop\PathTest\PathTest\PathTest\bin\Debug\test.txt
C:\Documents and Settings\Johan\Desktop\PathTest\PathTest\PathTest\bin\Debug\test.txt
C:\Documents and Settings\Johan\Desktop\PathTest\PathTest\PathTest\bin\Debug\folder1\test2.txt
This is the text in test1.text
This is the text in test2.text
So the conclusion of this, as you pointed out, using Path.DirectorySeparatorChar or several Path.Combine() is the way to go. Using Path.GetFullPath did not correct a windows-formated path as I thought. Thanks for your help.
http://johanmartensson.se - Home of MPEG4Watcher