473,403 Members | 2,359 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,403 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 7157
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.