0

im making an application loader which will allow you do have as many applications as you want saved in it, say for example you want to have Google Chrome in it, you press "add application" and you get an OpenFileDialog to select Chrome or any other app/program you want. the program then saves the path and name in .bin files and should load it when you click the button. it successfully loads websites but not applications, and the reason for that i think is that the program saves the file paths as

C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

instead of

C:/Program Files (x86)/Google/Chrome/Application/chrome.exe

at least thats what i think. anyway here's the code for "save" and "load":

Save:

if (metroTextBox1.Text == "" || metroTextBox2.Text == "")
{
    MessageBox.Show("You have to fill in both Name and Path first", "Invalid Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
    string[] name = { metroTextBox1.Text };
    string[] path = { metroTextBox2.Text };
    System.IO.File.WriteAllLines(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/appLoader/apps/appname1.bin", name);
    System.IO.File.WriteAllLines(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/appLoader/apps/apppath1.bin", path);
}

Load:

try
{                    
    string path = System.IO.File.ReadAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/appLoader/apps/apppath1.bin");
    Process.Start(path);
}
catch
{

}
maccettura
  • 10,514
  • 3
  • 28
  • 35
MoDz Trolls
  • 37
  • 2
  • 5

1 Answers1

1

Process.Start() can handle both, you don't have to convert any slashes or backslashes. Starting processes like this should work fine.

To hunt down the error, please check if the file exists (File.Exists(path)), if it can be run by you in Windows directly and of course (and most important) don't just catch the exception like you did but include the thrown exception like this:

catch (Exception ex)   // <-- !!
{
    // investigate (and log) the exception here.
    // note that catching all exceptions is not a good idea so narrow 
    // it down once you found the exceptions you have to care for.
}

Probably the file does simply not exist or cannot be run without having a working path set (this can be mandatory for some applications).

Waescher
  • 5,361
  • 3
  • 34
  • 51