473,666 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to open an application through an assigned filetype?

Know of any good tutorials to demonstrate how to assign a file extension to an applicatiand and how to open the file in the application when you doubleclick on the file in the OS

brgds Jesper.
Nov 16 '05 #1
6 2191
It's just a matter of adding some registry entries.
Translate this vb code to c#, should be pretty easy.
'// Registry windows api calls
Private Declare Function RegCreateKey& Lib "advapi32.D LL" Alias
"RegCreateK eyA" (ByVal hKey As Long, ByVal lpszSubKey As String, lphKey As
Long)
Private Declare Function RegSetValue& Lib "advapi32.D LL" Alias
"RegSetValu eA" (ByVal hKey As Long, ByVal lpszSubKey As String, ByVal
fdwType As Long, ByVal lpszValue As String, ByVal dwLength As Long)
'// Required constants
Private Const HKEY_CLASSES_RO OT = &H80000000
Private Const MAX_PATH = 256&
Private Const REG_SZ = 1

'// procedure you call to associate the tmg extension with your program.
Private Sub MakeDefault()
Dim sKeyName As String '// Holds Key Name in registry.
Dim sKeyValue As String '// Holds Key Value in registry.
Dim ret As Long '// Holds error status if any from API calls.
Dim lphKey As Long '// Holds created key handle from RegCreateKey.

'// This creates a Root entry called "TextMagic"
sKeyName = "TextMagic" '// Application Name
sKeyValue = "TextMagic Document" '// File Description
ret = RegCreateKey&(H KEY_CLASSES_ROO T, sKeyName, lphKey)
ret = RegSetValue&(lp hKey&, Empty, REG_SZ, sKeyValue, 0&)

'// This creates a Root entry called .tmg associated with "TextMagic" .
sKeyName = ".tmg" '// File Extension
sKeyValue = "TextMagic" '// Application Name
ret = RegCreateKey&(H KEY_CLASSES_ROO T, sKeyName, lphKey)

ret = RegSetValue&(lp hKey, Empty, REG_SZ, sKeyValue, 0&)

'//This sets the command line for "TextMagic" .
sKeyName = "TextMagic" '// Application Name
If Right$(App.Path ,1) = "\" Then
sKeyValue = App.Path & App.EXEName & ".exe %1" '// Application Path
Else
sKeyValue = App.Path & "\" & App.EXEName & ".exe %1" '// Application
Path
End If
ret = RegCreateKey&(H KEY_CLASSES_ROO T, sKeyName, lphKey)
ret = RegSetValue&(lp hKey, "shell\open\com mand", REG_SZ, sKeyValue,
MAX_PATH)
End Sub

Private Sub Form_Load()
'// ensure we only register once. When debugging etc, remove the
SaveSetting line, so your program will
'// always attempt to register the file extension
If GetSetting(App. Title, "Settings", "RegisteredFile ", 0) = 0 Then
'// associate tmg extension with this app
MakeDefault
SaveSetting App.Title, "Settings", "RegisteredFile ", 1
End If
End Sub

"Jesper." <an*******@disc ussions.microso ft.com> wrote in message
news:A6******** *************** ***********@mic rosoft.com...
Know of any good tutorials to demonstrate how to assign a file extension
to an applicatiand and how to open the file in the application when you
doubleclick on the file in the OS.

brgds Jesper.

Nov 16 '05 #2
Hi Jesper,

Not sure how to assign file type, but what happens when you click on a
"known" file is that the program is launched with the name of the file as
the first argument in the argument list.

public static void Main(string[] args)
{
if(args.Length > 0)
Application.Run (new Form1(args[0]));
else
Application.Run (new Form1());
}

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Morten Wennevik wrote:
Hi Jesper,

Not sure how to assign file type, but what happens when you click on a
"known" file is that the program is launched with the name of the
file as the first argument in the argument list.


This isn't necessarily true, although it is a typical behavior. When a file
assocation is created there are a set of registry keys that get added to the
registry. These keys contain the information used by the Windows OS as to
what to do when a file of that type is executed. This includes command
information. Often the command info may simply be the name of some
application followed by a %1, instructing Windows to pass the file that was
double clicked as the command argument. However there can certainly be
other arguments listed in the file association as well that may get passed
on the command line. The application may also use DDE, in which case
typically you will not see the file name passed on the command line at all.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.

Nov 16 '05 #4
Yeah, I remember seeing something like this in the registry.

I know Internet Explorer reacts differently to Process.Start and passing
the url directly to iexplore.exe compared to passing the url directly to
windows (the latter overwrites an already existing IE window, while the
former opens a new window). Not sure why though.

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #5
Morten Wennevik wrote:
Yeah, I remember seeing something like this in the registry.

I know Internet Explorer reacts differently to Process.Start and
passing the url directly to iexplore.exe compared to passing the url
directly to windows (the latter overwrites an already existing IE
window, while the former opens a new window). Not sure why though.


That's an IE setting (although I guess we're getting offtopic here since
we're now into the workings of windows and IE rather than coding). In the
IE advanced settings under browsing you can select or unselect the option to
reuse browser windows. So in the former you are specifically invoking an
iexplore.exe process as an executable with command line, in the latter you
are telling windows to figure out what to do with the command.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.

Nov 16 '05 #6
Ah, thanks, it has been bugging me for some time :)

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
107938
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
7
8347
by: kids_pro | last post by:
I found FileInfo expose alot of methods & properties. However I can't get FileType from FileInfo I can only get File extension. How can I get fileType any build-in library allow me to do that? If not please advice on what is the best way to get file type. Many thanks, kids
1
3695
by: Bon | last post by:
Hello all I create a form with three buttons in MS Access 2000. They are Open Excel Template, Save Draft and Save Final. When I click the Open Excel Template button, the Excel template will be opened. Inside the Excel template, I have assigned a draft watermark to the Print icon. When the Print icon is clicked, the draft watermark and print dialog box is shown. After the user print/edit data in the Excel template, s/he has to click
2
4236
by: Seok Bee | last post by:
Dear Experts, In my web application, I am having a button to open a file located in the server. When I click on the button to view the file, I received the following error message: ---------------------------------------------------------- Exception from HRESULT: 0xC004800A Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and...
3
2350
by: Mark.V.Sullivan | last post by:
I have encountered the same problem another posted about several months ago. Unfortunately, there was no result posted on the old thread. I will let the original message text stand and ask if anyone can help me with this.. "I have created a deployment project for a .NET program which opens a file with a custom extension. I have added the file type to the deployment project. After installation, double clicking a file with that...
1
1374
by: mekdam | last post by:
I've made an application and associated a filetype to it using the registry. When I double click the data file, it opens the application but doesn't load the data from the file, how do I fix this? thank you.
11
1944
by: MLH | last post by:
The following procedures found at http://ffdba.com/downloads/Send_Mail_With_Outlook_Express.htm are meant to work together in harmony to effect eMail sends via OE. The last procedure (FN SplitB) fails on its last line which is meant to assign the value of SplitB (a variant) the value of aSplit (an array dim'd as variant). That fails due to Type Mismatch. Anyone know how to get around this? Private Type MapiRecip Reserved As Long
0
1226
by: colin.steadman | last post by:
If I right click on a ASP file in Explorer and choose EDIT, Windows opens a new instance of MSE.EXE and opens the file in that. What I'd like it to do is simply goto the existing open MSE application and open the file in a new tab. I cant find the correct settings to do this is 'FILE TYPES', could anyone help? My current settings are (In Explorer: TOOLS FOLDER OPTIONS FILE TYPES ASP FILE ADVANCED EDIT EDIT):
3
2905
by: MLH | last post by:
With Application.FileSearch .NewSearch .LookIn = "C:\My Documents" .SearchSubFolders = True .FileName = "Run" .MatchTextExactly = True .FileType = msoFileTypeAllFiles End With My code pukes complaining that msoFileTypeAllFiles
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.