How to execute a custom file with C#?
I'm writing a application by C#, in application i creat a file with extension is .wws and i want when user double click on this file then my program can realize and execute to read it. Somebody can help me?.
6 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Tom Diann16 pointsPosted Dec 27, 2005, 10:00 PM EST
Well, you can't do it ,you have to write another program that opens your wws file.The operating system didn't recognize it and can't execute it directly!
Long Thanh25 pointsPosted Dec 27, 2005, 11:05 PM EST
Could you show me another way if don't use C#?, How make os can realize this file like when you double click on *.txt file then Notepad will be invoke to read file with extension is .txt
AnttiRank #9,295 · 208 pointsPosted Dec 28, 2005, 4:14 AM EST
>>Well, you can't do it ,you have to write another program that opens your wws file.The operating system didn't recognize it and can't execute it directly!
That doesen't really make sense to me, of course C# app must be able to register a file type to it. In installation phase you must somehow associate the filetype with your program. If C# doesen't have method to associate the filetype with program, you must find some WinAPI function to do it. Assosiationg the filetype has nothing to do with the programming language, it is Windows's feature.
>>write another program that opens your wws file
How the other program changes the situation? It have to register the filetype anyway.
Edit:
A solution
I quickly searched google, and found one possible answer. I have no time to try it, but you take it a try: http://www.vbcity.com/forums/topic.asp?tid=72258. So basically best way to register a filetype seems to be the use of an installation project created with visual studio. When you install the program, your files can be associated. When you uninstall the program, the file association is also uninstalled. If you get that working, let us know. The other way to associate the filetype is to modify registry values directly, but if installer does it for you, it is better choice.But i presume you must have somekind of an interface in your program to open the file that way. My guess is that your program will just open if you don't make any modifications to it. It would be logical that windows passes the filenames to Main method of the program, so you can open the file in program.
static void Main(string[] args) { if (args.Length > 0) { //open the file(s) here, remember to use all necessary sanity checks and try-catches foreach (string filename in args) { //open each file } } else { //start program normally } }>>How make os can realize this file like when you double click on *.txt file then Notepad will be invoke to read file with extension is .txt
OS keeps file associations in registry, so that way OS can tell what program to call. You can modify these associations by hand, in Windows Explorer Tools->Folder Options...->File Types->Advanced.
Long Thanh25 pointsPosted Dec 28, 2005, 4:04 PM EST
AnttiRank #9,295 · 208 pointsPosted Dec 28, 2005, 10:40 PM EST
No problem;)
Well, there actually is. I encountered a problem myself with this same issue: I use Visual C# Express 2005, and it has no such thing as Installation Project! I don't know how to do the extension associations with Visual C# Express 2005, someone have any knowledge about that?
Do I have to use some 3rd party installation program (any free & good will do)?
Long Thanh25 pointsPosted Dec 29, 2005, 4:45 PM EST