Open With....

rifter1818

Junior Contributor
Joined
Sep 11, 2003
Messages
255
Location
A cold dark place
Couple of (hopefully) quick questions here.
1)I've been using Process.Start(filename) to open programs and files fine for a while now however if its a filetype with no known extension is there anyway to open the windows openwith dialoge? or do i have to code my one in which case how do i access the list normally provided by windows in said dialoge.
2)If i was to write a text editor, (C#) how would i access the data from a file opened with my text editor.
3) How would i (through code/ in the setup program) tell windows to use my application for certain file extensions?
C# for answers is appreciated but any answer is great thanks in advance.
 
The answers you seek are in the registry. There is a whole slew of keys devoted to known file extensions and what programs use them and such.

You can tell windows to use your app with a certian file exension (associate the file extension with you app) when you deploy. It's an option when your putting together your install package.

I'm unsure about your first question, but I hope thsese other these thoughts help a bit. They should at least push you in the right direction.
 
To clarify

1) When you right click on a file and select "Open With" (or double click on a file with an unknown file extension) windows opens up a form with a list of programs and a browse feature to choose what program to open that file with... Just wondering if i can send a filename to that or if i have to code my own.
 
in thge windows sdk (Windows Shell and Controls)

Arbitrary File Types
Creating a File Association
Verbs and File Associations

go to pinvoke.net to get c# introp p\invoke code
 
Explorer Icons

On this subject, is there a way to read which icons go with which file types? Kind of like a cusom Explorer type app. Can I get the icon definitions from somewhere without having to compile a collection of my own?
 
i too want an answer to the following question:

I've been using Process.Start(filename) to open programs and files fine for a while now however if its a filetype with no known extension is there anyway to open the windows "openwith" dialoge? or do i have to write a code in which case how do i access the list normally provided by windows in said dialoge.

If anyone knows an answer to this question, please reply at the earliest possible... Thanx in advance:)

rifter1818 said:
Couple of (hopefully) quick questions here.
1)I've been using Process.Start(filename) to open programs and files fine for a while now however if its a filetype with no known extension is there anyway to open the windows openwith dialoge? or do i have to code my one in which case how do i access the list normally provided by windows in said dialoge.
2)If i was to write a text editor, (C#) how would i access the data from a file opened with my text editor.
3) How would i (through code/ in the setup program) tell windows to use my application for certain file extensions?
C# for answers is appreciated but any answer is great thanks in advance.
 
Here's C# code that uses the "open with" dialog.

ported from http://blogs.msdn.com/oldnewthing/archive/2004/11/26/270710.aspx
and http://groups.google.com/group/micr...mer.ui/browse_thread/thread/8dde98bae84136fc/.

Code:
using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication6
{
	[Serializable]
	public struct ShellExecuteInfo 
	{
		public int Size;
		public uint Mask;
		public IntPtr hwnd;
		public string Verb;
		public string File;
		public string Parameters;
		public string Directory;
		public uint Show;
		public IntPtr InstApp;
		public IntPtr IDList;
		public string Class;
		public IntPtr hkeyClass;
		public uint HotKey;
		public IntPtr Icon;
		public IntPtr Monitor;
	}

	class Class1
	{
		[DllImport("shell32.dll", SetLastError=true)]
		extern public static bool ShellExecuteEx(ref ShellExecuteInfo lpExecInfo);

		public const uint SW_NORMAL = 1;

		static void OpenAs(string file) 
		{ 
			ShellExecuteInfo sei = new ShellExecuteInfo();
			sei.Size = Marshal.SizeOf(sei); 
			sei.Verb = "openas"; 
			sei.File = file; 
			sei.Show = SW_NORMAL; 
			if(!ShellExecuteEx(ref sei))
				throw new System.ComponentModel.Win32Exception();
		} 

		[STAThread]
		static void Main(string[] args)
		{
			OpenAs(@"C:\odbcconf.log");
			return;
		}
	}
}

Unfortunately, I couldn't find a way to prevent the method from returning immediately =(
 
You could also pass in the path to the EXE to the StartInfo property and also specify the path to the file. Most programs will take a file path as a command line argument.
 
Back
Top