473,769 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB .net Associate file with Program

3 New Member
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 7170
krodman
12 New Member
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
1875
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 an illegal operation." I am running this on Windows 98 platform. {If not, I'll post this issue to a Borland newsgroup.} #include <iostream> #include <fstream>
0
1851
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 Sharepoint portal Server B whose domain is stood alone. However, the program is unable to upload file over 2MB, when the file size exceeds, timeout will occur! I have tried to make a change in the web.config and machine.config of sharepoint portal...
5
1822
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 Answer4
0
1841
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 if asked to !!).. 3]want an output file,say OUT, where X and Y are interchanged i.e above 'X' values in'Y' and 'Y' values in 'X'..but 'Z' remain same( and display if asked to!!) 4]get average of values(sum of numbers/number of items) in column Z...
4
2522
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 where my mistake is thanks. This is what I have so far. In a vendlib.h file I have // include file for project 3 //converts input to product_price int product_price(int);
1
1532
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 dimes and pennies print out a long string of numbers. I can't figure out were these numbers are coming from. If anyone can help I will be appreciated. This is my main.cpp code for the body of my program. #include<iostream> #include"vendlib.h"...
1
1150
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 application?(how get file name as well as where i can handle ) problem2 when i tried with big application (liking with so many dll and other files) it is crashing, i believe this may be happening due to
1
2200
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
1397
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
9589
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
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7408
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.