5 replies
by kaymaf Accepted solution
by mayurbhavsar45 Accepted solution
by sixlead Accepted solution
by sixlead Accepted solution
To create file association with your application takes two process:
1. You need associate your application's file type with windows registry so when a file clicked with your application's extension, windows will call your application.
This is can be done couple ways. Manually, In windows, if you right click on any file with any extension and choose 'Properties' you will see the type of file and which program opens it.
If you click 'change' next to it, you can modify which application will open the file when you click.
Easiest and automated way to this is to add a setup project to your application in Visual Studio. After customizing the settings for your setup, in solution explorer on right, right click on your setup project and choose 'view' you'll see, 'file system', 'registry', 'file types, etc.
Click on file Types, and add the file type extension(s) you'd like to associate with your application. This way, when your application is setup on windows, your file type extensions will be associated with your application.
2. You need to do some coding in your application to open its file types.
You should struct your code basically to get the file name and its extension and open it in your application. You can put all your code in form load event or a better way, to create them as functions and call them in Form Load event.
I'll give a simple example how to open a file with your file type extension as a text file.
Private Sub OpenFilesFromCommandLine()
Dim strExt As String
Dim fileContents As String
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
For i As Integer = 0 To CommandLineArgs.Count - 1
strExt = System.IO.Path.GetExtension(CommandLineArgs(i)) 'get the filename extension
Select Case strExt
Case ".kay" 'This is to open a file with associated extension *.kay
' If you need to associate your App to open any other extensions,
' you can create a case for it just like this.
fileContents = My.Computer.FileSystem.ReadAllText(CommandLineArgs(i))
TextBox1.Text = fileContents
TextBox1.Select(0, 0) 'This is a basic code to open text files, you can substitute this code
' according to file type your application needs to open.
Me.Text = GetFileName(CommandLineArgs(i)) & " - MyApp Name" 'In this part we get the file name with 'GetFileName' function and use it to display like 'MyApp Name - Somefile.kay' on the application.
ToolStripStatusLabel1.Text = CommandLineArgs(i)
Case Else 'This is to open any other file extensions that its extension not .kay
i.e it can any extension when you right click on a file and 'Open with'
' This is also usefull if you need to open a various file extensions
' associated with your application as a single type.
' For instance, if you associate file type extension with your application
' like, *.txt, *.text, *.readme and like, and they're all text files,
' you can use a single block of code to open them.
fileContents = My.Computer.FileSystem.ReadAllText(CommandLineArgs(i))
TextBox1.Text = fileContents
textbox.Select(0, 0)
' Me.Text = "MyApp Name -" & CommandLineArgs(i)
Me.Text = GetFileName(CommandLineArgs(i)) & " - MyApp Name"
ToolStripStatusLabel1.Text = CommandLineArgs(i)
End Select
Next
End Sub
'This is a function to to get the filename used
Private Function GetFileName(ByVal vStrFullPath As String) As String
Dim intPos As Integer
intPos = InStrRev(vStrFullPath, "\")
GetFileName = Mid$(vStrFullPath, intPos + 1)
End Function
And add OpenFilesFromCommandLine() to your application's form load event.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFilesFromCommandLine()
End Sub
by amartufo Accepted solution
Hey guys I have developed a audio player application in Visual Basic 2008, and it works perfectly, but I wondering on how to make extension so that I open any .MP3 file using my program.Note: I called my audio player Minox Player, and it works using WMP engine.I have write a code lines for registry file asocation that looks like this:
Public Sub ChecAssocation()
Try
My.Computer.Registry.ClassesRoot.CreateSubKey(".MP3").SetValue("", "MinoxPlayer", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey("MinoxPlayer\shell\open\comand").SetValue("", Application.ExecutablePath & " ""%1"" ", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey("MinoxPlayerDefaultIcon").SetValue("", Application.StartupPath & "\MP3.ico")
Catch ex As Exception
End Try
End Sub
but when I debug my app it's not working.But when I choose a program to play .mp3 files my program appears, and I can open file with in but there is nothing in my playlist.Any help please!
by the way thanks!....
This discussion is closed to new replies.
Trending Software posts
Sort by Trending