Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted

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

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • 2 weeks later...
Posted

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?

  • 1 year later...
Posted

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:)

 

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.

Posted

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/microsoft.public.win32.programmer.ui/browse_thread/thread/8dde98bae84136fc/.

 

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 =(

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...