473,320 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB .net Associate file with Program

3
I want to make a file associate with my program I just created. I'd like text files to open up my app instead but I don't know where to begin. I found a C# example, but am having a hard time converting.

The File With The Example
Above is the C# file. I would like it in VB(.net) if anyone wouldn't mind. Or if some one can help me find a tutorial online. (I'm still searching).

Thanks Everyone. I appreciate it. :)
Aug 3 '06 #1
1 7149
krodman
12
I've used this in the past, I can't remember where I got it from, but it works great.

Expand|Select|Wrap|Line Numbers
  1. Public Class Example
  2.  
  3.     Public Sub RegisterType()
  4.         Dim fileReg As New FileTypeRegistrar
  5.  
  6.         With fileReg
  7.             .FullPath = Path_To_Executable
  8.             .FileExtension = Extension_To_Register
  9.             .ContentType = "application/" & Your_Description
  10.             .IconIndex = Icon_Index_In_Application
  11.             .IconPath = Path_To_Executable
  12.             .ProperName = Name_Of_Executable
  13.             .CreateType()
  14.         End With
  15.  
  16.     End Sub
  17.  
  18. End Class
  19.  
  20. Public Class FileTypeRegistrar
  21.  
  22. #Region "Properties & Property Variables"
  23.     Private _ProperName As String
  24.     Public Property ProperName() As String
  25.         Get
  26.             Return _ProperName
  27.         End Get
  28.         Set(ByVal Value As String)
  29.             _ProperName = Value
  30.         End Set
  31.     End Property
  32.  
  33.     Private _ContentType As String
  34.     Public Property ContentType() As String
  35.         Get
  36.             Return _ContentType
  37.         End Get
  38.         Set(ByVal Value As String)
  39.             _ContentType = Value
  40.         End Set
  41.     End Property
  42.  
  43.     Private _FullPath As String
  44.     Public Property FullPath() As String
  45.         Get
  46.             Return _FullPath
  47.         End Get
  48.         Set(ByVal Value As String)
  49.             _FullPath = Value
  50.         End Set
  51.     End Property
  52.  
  53.     Private _FileExtension As String
  54.     Public Property FileExtension() As String
  55.         Get
  56.             Return _FileExtension
  57.         End Get
  58.         Set(ByVal Value As String)
  59.             _FileExtension = Value.Replace(".", "")
  60.         End Set
  61.     End Property
  62.  
  63.     Private _IconPath As String
  64.     Public Property IconPath() As String
  65.         Get
  66.             Return _IconPath
  67.         End Get
  68.         Set(ByVal Value As String)
  69.             _IconPath = Value
  70.         End Set
  71.     End Property
  72.  
  73.     Private _IconIndex As Integer
  74.     Public Property IconIndex() As Integer
  75.         Get
  76.             Return _IconIndex
  77.         End Get
  78.         Set(ByVal Value As Integer)
  79.             _IconIndex = Value
  80.         End Set
  81.     End Property
  82. #End Region
  83.  
  84. #Region "Public Methods"
  85.     Public Sub CreateType()
  86.         Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
  87.         Dim Ext As String = "." & FileExtension.ToLower
  88.         Dim extKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(Ext)
  89.  
  90.         extKey.SetValue("", fileName)
  91.         extKey.SetValue("Content Type", ContentType)
  92.         extKey.Close()
  93.  
  94.         Dim mainKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(fileName)
  95.         Dim defIconKey As RegistryKey = mainKey.CreateSubKey("DefaultIcon")
  96.  
  97.         defIconKey.SetValue("", IconPath & ", " & IconIndex)
  98.         defIconKey.Close()
  99.  
  100.         Dim shellKey As RegistryKey = mainKey.CreateSubKey("shell")
  101.         Dim OpenKey As RegistryKey = shellKey.CreateSubKey("Open")
  102.         Dim cmdKey As RegistryKey = OpenKey.CreateSubKey("command")
  103.  
  104.         cmdKey.SetValue("", """" & FullPath & " %1""")
  105.         cmdKey.Close()
  106.         OpenKey.Close()
  107.         shellKey.Close()
  108.         mainKey.Close()
  109.  
  110.     End Sub
  111.  
  112.     Public Sub DeleteType()
  113.         Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
  114.         Dim Ext As String = "." & FileExtension.ToLower
  115.  
  116.         Registry.ClassesRoot.DeleteSubKey(Ext)
  117.         Registry.ClassesRoot.DeleteSubKey(fileName)
  118.  
  119.     End Sub
  120. #End Region
  121.  
  122. End Class
  123.  
Aug 13 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Thomas Matthews | last post by:
Is there anything technically wrong with the code below? I compiled it with g++ 3.3.1 and it executes with no errors. I compiled it with bcc32 5.6 and it executes with "This program has performed...
0
by: cherry | last post by:
Dear All, I have written a program in sharepoint, in which will call a Web Service of another Sharepoint portal server so that documents from sharepoint portal server A can push document to...
5
by: ComicCaper | last post by:
Hi all, I use a quiz program that accepts a text file for questions and answers in this format: Question Answer1 <----is the correct answer. Quiz randomizes answers. Answer2 Answer3...
0
by: jisha | last post by:
i want to get code for a program in visual c++ where : 1]take the name of directory say DIR 2]get a file ,say IN from that directory which has 3 column (say X, Y and Z) and many rows( display this...
4
by: gdarian216 | last post by:
I am doing a multi file program and I got it to work correctly in a single file but when I split it up it isn't working properly. I keep getting errors when i compile. Can anyone help me figure out...
1
by: gdarian216 | last post by:
I am writing a multifile program and it worked when it was all in one file. I have gotten all of the errors out of the program except when I go to output the change the quarters are right but the...
1
by: zidansoft | last post by:
I created appropriate registry entries(shell\open\command) . my simple application lunching with that particular extension . problem 1 how i can handle that particular file from my...
1
by: sadanand | last post by:
Hi, I am a beginer to perl progmig. When I run the following program.. use File::Find; use File::Stat; use Time::Local;
2
by: rajak20pradeep | last post by:
Hello, i cannot solve this program. Q. Write a program to find and count article(a.an ,the) in a text file .
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.