Support Forums
vb.net associated files? - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: vb.net associated files? (/showthread.php?tid=3477)



vb.net associated files? - thanasis2028 - 12-10-2009

I am using VB.net to create an app, and I have associated .mvt files with my application. But how can I tell my app what to do when the user opens(double-clicks) a .mvt file? I need a way for my app to detect that a .mvt was actually double-clicked and not the app itself and read the .mvt that was double-clicked when the app starts. Can you help me ?


RE: vb.net associated files? - Nonmod - 12-10-2009

(12-10-2009, 05:34 AM)thanasis2028 Wrote: I am using VB.net to create an app, and I have associated .mvt files with my application. But how can I tell my app what to do when the user opens(double-clicks) a .mvt file? I need a way for my app to detect that a .mvt was actually double-clicked and not the app itself and read the .mvt that was double-clicked when the app starts. Can you help me ?

if vb.net is c#-like ,search for main entry point for your program(in c# its Main()),smth like that.
The trick is-when you doubleclick a file,windows instantly sends this file path to associated application as variable named %1.
If you know where is you app's entry point,=, add a argument to that function-may be smth like Main(eventargs e).
When you find it,put there simple if statement.here's pseudocode:
Code:
if strFilePath != null
  do something with file
else
  open app w/o file



RE: vb.net associated files? - thanasis2028 - 12-11-2009

(12-10-2009, 09:26 AM)Nonmod Wrote: if vb.net is c#-like ,search for main entry point for your program(in c# its Main()),smth like that.
The trick is-when you doubleclick a file,windows instantly sends this file path to associated application as variable named %1.
If you know where is you app's entry point,=, add a argument to that function-may be smth like Main(eventargs e).
When you find it,put there simple if statement.here's pseudocode:
Code:
if strFilePath != null
  do something with file
else
  open app w/o file
Ok, it was rather different but after a lot of search I found it.
The 2nd parameter of the app is the file opened. So, here is the code:
Code:
'Next code will find if a .mvt was opened
        Dim s() As String = System.Environment.GetCommandLineArgs()'finds parameters and stores it to a string array
        Try
            If InStr(s(1), ".mvt") = s(1).Length - 3 Then  's(1) is the file that was opened
               'open file     'InStr(s(1), ".mvt") = s(1).Length - 3 checks if file has our extension (.mvt)
            End If
        Catch ex As Exception
            '.exe was opened directly and s(1) does not exist
        End Try