Open file with associated application

Related searches

i want to ask for help with opening a file from c# app with associated app. I tried this:

      ProcessStartInfo pi = new ProcessStartInfo(file);
      pi.Arguments = Path.GetFileName(file);
      pi.UseShellExecute = true;
      pi.WorkingDirectory = Path.GetDirectoryName(file);
      pi.FileName = file;
      pi.Verb = "OPEN";
      Process.Start(pi);

or this:

      Process.Start(file);

where string file in both examples represents full path to the file trying to open. Now, everything is working well, except the (jpg) images with ACDSee app. Irfanview associations works well, MS office documents too. After trying to open the jpg image associated with acdsee it just runs the acdsee in the notification area and does not open the file.

I discovered, that in the registry CLASSES_ROOT for *.jpg images, there is an ACDSee.JPG value as associated app, and under this key there is in the shell->Open->Command a path:

"C:\Program Files\ACD Systems\ACDSee\ACDSee.exe" /dde

and I thing that this weird /dde is the reason, why i cannot open the file. I realized that in the same reg key shell->Open there is some DDEExec key entry with value [open("%1")]

For Irfan view or other checked app there is not a ddeexec, just the normal command like

"C:\Program Files (x86)\IrfanView\i_view32.exe" "%1"

that can be run from command line after swaping the %1 for file name, but I could not run the command from acdsee entry in the command line :(

So my question is, how can I set up the ProcessStartInfo object to ensure that it will run all the files as it would be in the explorer by doubleclick, the standards and this DDEExec ones? Is there something other like DDEExec that I shoul be aware of? thanks and sorry for my EN

Just write

System.Diagnostics.Process.Start(@"file path");

example

System.Diagnostics.Process.Start(@"C:\foo.jpg");
System.Diagnostics.Process.Start(@"C:\foo.doc");
System.Diagnostics.Process.Start(@"C:\foo.dxf");
...

And shell will run associated program reading it from the registry, like usual double click does.

Open file with associated application, Windows 10: Change the Default Programs for Opening Files tablet than the desktop applications you used to install from .exe files on CDs (or different file types and the default programs they're currently associated with. This example demonstrates how to open file with an associated program. It shows, how to open text document in notepad, how to open image in a default viewer or how to open url address in a default web browser. Applications are launched using Process.Start method. The file path or url is passed as a parameter. [C#] // open text file in notepad (or another default text editor) System.Diagnostics.

In .Net Core (as of v2.2) it should be:

new Process
{
    StartInfo = new ProcessStartInfo(@"file path")
    {
        UseShellExecute = true
    }
}.Start();

Related github issue can be found here

Windows 10: Change the Default Program for Opening Files, works for xp and other windows (95 or higher) If it does not work, you haven't associated that extention type with a program. Our first method uses it to quickly associate file types with programs. Open Control Panel and navigate to Programs. Select Default Programs and Associate a file type or protocol with a specific program. Find the file type that you want to change on the left and highlight it. Select Change program in the top right.

This is an old thread but just in case anyone comes across it like I did. pi.FileName needs to be set to the file name (and possibly full path to file ) of the executable you want to use to open your file. The below code works for me to open a video file with VLC.

var path = files[currentIndex].fileName;
var pi = new ProcessStartInfo(path)
{
    Arguments = Path.GetFileName(path),
    UseShellExecute = true,
    WorkingDirectory = Path.GetDirectoryName(path),
    FileName = "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe",
    Verb = "OPEN"
};
Process.Start(pi)

Tigran's answer works but will use windows' default application to open your file, so using ProcessStartInfo may be useful if you want to open the file with an application that is not the default.

Open file with default application from command line, Opening files with different applications. When you open a file in Windows, it will usually open in the default application for that type of file. For example, a photo� Step 1: Right-click on a file of the type you wish to change the association for. Step 2: Select Open with from the resulting menu.

File association, How to Change File Associations in Windows XP. Go to Start > Control Panel to open Control Panel. Choose Appearance and Themes . You'll only see that link if you're using the Category View of Control Panel. If you're instead using the Classic Select Folder Options near the bottom of the window.

Windows Basics: Opening Files with Different Applications, I want a simple and effective method to show the arguments (associated files) to open. How to associate files with C# program? I present the step by step procedure below. 1. Step-Create the general form. Create a new Windows Forms application in Visual Studio.

open: Launches an application. If this file is not an executable file, its associated application is launched. print: Prints the document file. properties: Displays the object's properties. runas: Launches an application as Administrator. User Account Control (UAC) will prompt the user for consent to

Comments
  • It seems like he already tried that with Process.Start(file);.
  • "So my question, how can I set up the ProcessStartInfo object to ensure that it will run all the files as it would be in the explorer by doubleclick": the answer is that. He used command line arguments, whatever... but not direct invokation, as much as I see.
  • @Tigran Mario is right, as I wrote I tried your suggestion as the second example... i wanted to ask my question in manner that clearly this is not the right sollution, as the jpg is not opened!
  • @Zavael: on my machine it opens windows default editor, so I think on your system it should open simply the latest software installed and associated with that format.
  • @Tigran as i wrote, if I have Irfanview, its ok, if I have word documents, its ok, even windows viewer works fine, but they have their commands in one reg value... acdsee has there some /dde argument and an DDEExec registry key, tha I think is for build the command together and therefore its not working... and its not only on my machine.. try to install acdsee 4 and than run the code
  • (: a comment on an old response to an old thread :) Tigran's answer runs the most recently associated program for each file's extensions. Tree's answer forces it to use vlc.exe. Zavael's question is about trouble he is only having with ACDSee.exe and how it sets up its extension association. I think the authors of ACDSee need to be contacted about this.
  • it was an older version of acdsee and I did not verified it with new one so I didnt contact them, just for the info :)