Execute files included in Resource folder

Posted by Sumeet Pujari on Stack Overflow See other posts from Stack Overflow or by Sumeet Pujari
Published on 2012-10-26T11:44:01Z Indexed on 2012/10/31 23:01 UTC
Read the original article Hit count: 164

Filed under:
|
|

In WPF application where I have included some files in resources, I want to execute them on a button click. How do I specify a path in Process.Start().

private void button1_Click_2(object sender, RoutedEventArgs e)
{
    Process.Start("test.txt");    
}

Or is there any other way?


private void button1_Click_2(object sender, RoutedEventArgs e)
{
    string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\test.txt";
    if (File.Exists(path))
    {
        Process.Start(new ProcessStartInfo(path));
    }
    else
    {
        MessageBox.Show("No file found"+path);
    }

I added a message box and it showed No files found. :(

EDIT: I Tried to check the path after publishing and this what i got. No File Found With a Path - C:\Users\Administrator\AppData\Local\Apps\2.0... test.txt

Before I published the Application I got a path which id No File Found at ..project..\bin\Debug\test.txt which is obvious since my Resource file not included there its Under a Resource Folder and not Debug when i add a test file in debug it open without any problem.

Can someone Help throwing some light on this case.

EDIT:

I want to open a file from Resource directory @ C:\Users\Administrator\Documents\Visual Studio 2010\Projects\FastFix\FastFix\Resources Which would be included in my project when i am going to publish it is going to run as a standalone application without installation.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf