Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Open a file when it is double clicked

Open a file when it is double clicked

Scheduled Pinned Locked Moved Visual Basic
helpquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chatura Dilan
    wrote on last edited by
    #1

    I have created a small word processing application, and I have created a new file extension (“.sln”) to save files. Like RichTextBox1.Save (FilePath & “/myFile.sln”) Now, I want to open myFile.sln using my word processing application when I double click Myfile.sln :confused: Do you know any codes to do that? Please help me chatura

    N J 2 Replies Last reply
    0
    • C Chatura Dilan

      I have created a small word processing application, and I have created a new file extension (“.sln”) to save files. Like RichTextBox1.Save (FilePath & “/myFile.sln”) Now, I want to open myFile.sln using my word processing application when I double click Myfile.sln :confused: Do you know any codes to do that? Please help me chatura

      N Offline
      N Offline
      noshaba mariam
      wrote on last edited by
      #2

      If u want to open file with extension .sln in text box then in my opinion u need to copy the text of the file to clip board and then paste it in text box. In this way it would appear as if file is opening directly in text box :)

      1 Reply Last reply
      0
      • C Chatura Dilan

        I have created a small word processing application, and I have created a new file extension (“.sln”) to save files. Like RichTextBox1.Save (FilePath & “/myFile.sln”) Now, I want to open myFile.sln using my word processing application when I double click Myfile.sln :confused: Do you know any codes to do that? Please help me chatura

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Chatura Dilan wrote:

        Now, I want to open myFile.sln using my word processing application when I double click Myfile.sln

        Do you mean when you double click in windows explorer? If so this is a windows setting for the default application associated with a file extension. (eg, for most people .doc will open with MS Word). Tip: If you Right click a file you can choose "Open with..." then simply brose for your exe. As long as your app supports executing with an argument providing the path to the file then all should be dandy (eg, c:\myapp.exe "c:\my files\myfile.sln").

        C 1 Reply Last reply
        0
        • J J4amieC

          Chatura Dilan wrote:

          Now, I want to open myFile.sln using my word processing application when I double click Myfile.sln

          Do you mean when you double click in windows explorer? If so this is a windows setting for the default application associated with a file extension. (eg, for most people .doc will open with MS Word). Tip: If you Right click a file you can choose "Open with..." then simply brose for your exe. As long as your app supports executing with an argument providing the path to the file then all should be dandy (eg, c:\myapp.exe "c:\my files\myfile.sln").

          C Offline
          C Offline
          Chatura Dilan
          wrote on last edited by
          #4

          Yes I mean that I know that. but it does not work. My application is already associate with .sln files. but when I double click 'myfile.sln', my application starts and loads a new document file. but it does not load 'myfile.sln' chatura

          J O 2 Replies Last reply
          0
          • C Chatura Dilan

            Yes I mean that I know that. but it does not work. My application is already associate with .sln files. but when I double click 'myfile.sln', my application starts and loads a new document file. but it does not load 'myfile.sln' chatura

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            First you have to understand what windows does (by default) when you associate a file extension with an executable program. It executes the .exe passing the file name as the first parameter like this: C:\myFolder\MyExecutable "C:\myData\the_file_I_d_clicked.sln" So, you need to support arguments in your executable, and if the first argument is a valid location of a file, then open it at startup instead of a blank document. Here, I wrote a little example for you: I had a textbox and a button, on the button I have this code: String str = tbInput.Text; StreamWriter sr = new StreamWriter(@"C:\test.abc"); sr.Write(str); sr.Close(); Then in my app start code I have this (note: string[] args are the arguments passed into the exe)

            if(args.Length>0)
            {
            	string path = args[0];
            	if(Path.GetExtension(path) == ".abc" && File.Exists(path))
            	{
            		StreamReader sr = new StreamReader(path);
            		this.tbInput.Text = sr.ReadToEnd();
            		sr.Close();
            	}
            }
            

            sorry, forgot which forum I was on...here in VB.NET

            if(args.Length>0)then
            
            	string path = args[0]
            	if(Path.GetExtension(path) = ".abc" and File.Exists(path))then
            	
            		StreamReader sr = new StreamReader(path)
            		this.tbInput.Text = sr.ReadToEnd()
            		sr.Close()
            	end if
            end if
            

            -- modified at 8:24 Thursday 2nd March, 2006

            C 1 Reply Last reply
            0
            • C Chatura Dilan

              Yes I mean that I know that. but it does not work. My application is already associate with .sln files. but when I double click 'myfile.sln', my application starts and loads a new document file. but it does not load 'myfile.sln' chatura

              O Offline
              O Offline
              Omar Mallat
              wrote on last edited by
              #6

              Hi, If you need to relate an extension type to your application, you can do it using the windows utilites, or a vb code. in windows, it's done using folder options in explorer. but in code I can help you, you should create some keys in the registry, it's very simple. you can also assign an Icon and add commands to it when you right click on a file like Edit in MyApplication or CompileFile... tell me if you need it. but if you need that after having the type related, how to open it so: when you double click on file, it's automatically sent to the related application as arguments. you can select multiple files and press enter so all files will be sent to you application as array of arguments. you can catch all argument while loading application. someone tell you how using C# but can you tell wich version of VB you use?:confused: is it vb.net or vb2005? so I can help you also...:cool: OmarMallat

              C 1 Reply Last reply
              0
              • O Omar Mallat

                Hi, If you need to relate an extension type to your application, you can do it using the windows utilites, or a vb code. in windows, it's done using folder options in explorer. but in code I can help you, you should create some keys in the registry, it's very simple. you can also assign an Icon and add commands to it when you right click on a file like Edit in MyApplication or CompileFile... tell me if you need it. but if you need that after having the type related, how to open it so: when you double click on file, it's automatically sent to the related application as arguments. you can select multiple files and press enter so all files will be sent to you application as array of arguments. you can catch all argument while loading application. someone tell you how using C# but can you tell wich version of VB you use?:confused: is it vb.net or vb2005? so I can help you also...:cool: OmarMallat

                C Offline
                C Offline
                Chatura Dilan
                wrote on last edited by
                #7

                Sure... I'm using VB.Net 2005 I’m very sorry do not try to change the application which associate “.sln” files. They are solution files. I changed my extension. it is “.shln” files. Sorry for my delay chatura

                1 Reply Last reply
                0
                • J J4amieC

                  First you have to understand what windows does (by default) when you associate a file extension with an executable program. It executes the .exe passing the file name as the first parameter like this: C:\myFolder\MyExecutable "C:\myData\the_file_I_d_clicked.sln" So, you need to support arguments in your executable, and if the first argument is a valid location of a file, then open it at startup instead of a blank document. Here, I wrote a little example for you: I had a textbox and a button, on the button I have this code: String str = tbInput.Text; StreamWriter sr = new StreamWriter(@"C:\test.abc"); sr.Write(str); sr.Close(); Then in my app start code I have this (note: string[] args are the arguments passed into the exe)

                  if(args.Length>0)
                  {
                  	string path = args[0];
                  	if(Path.GetExtension(path) == ".abc" && File.Exists(path))
                  	{
                  		StreamReader sr = new StreamReader(path);
                  		this.tbInput.Text = sr.ReadToEnd();
                  		sr.Close();
                  	}
                  }
                  

                  sorry, forgot which forum I was on...here in VB.NET

                  if(args.Length>0)then
                  
                  	string path = args[0]
                  	if(Path.GetExtension(path) = ".abc" and File.Exists(path))then
                  	
                  		StreamReader sr = new StreamReader(path)
                  		this.tbInput.Text = sr.ReadToEnd()
                  		sr.Close()
                  	end if
                  end if
                  

                  -- modified at 8:24 Thursday 2nd March, 2006

                  C Offline
                  C Offline
                  Chatura Dilan
                  wrote on last edited by
                  #8

                  Thank you for your reply. I’m trying to change it according to my application.. Sorry for my delay chatura

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups