"Open with" question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kimiraikkonen

    #1

    "Open with" question

    Hi,
    I have small project which opens text files via inside the project but
    i want to associate this app for every text file. To have a test, if i
    right click on a text file -then "open with" -my application...
    but my app's text area(textbox,wh ere the text data is loaded into. )
    is opened blank, nothing is displayed except a general view of my
    project app

    How can i make "open with" association to display text with my project
    properly?

    Thanks.
  • zacks@construction-imaging.com

    #2
    Re: "Open with" question

    On Dec 18, 1:38 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
    Hi,
    I have small project which opens text files via inside the project but
    i want to associate this app for every text file. To have a test, if i
    right click on a text file -then "open with" -my application...
    but my app's text area(textbox,wh ere the text data is loaded into. )
    is opened blank, nothing is displayed except a general view of my
    project app
    >
    How can i make "open with" association to display text with my project
    properly?
    All an "open with" association does is launch the associated
    application with the complete path to the file clicked on in the
    Command Line. It is up to your application to see that there is a file
    name in the command line and process it appropriately.

    Comment

    • Mattias Sjögren

      #3
      Re: &quot;Open with&quot; question

      >How can i make "open with" association to display text with my project
      >properly?
      Your application would likely accept the path to the file on the
      command line. You then parse the command line during application
      startup, load the file and display the content in the text box.


      Mattias

      --
      Mattias Sjögren [C# MVP] mattias @ mvps.org
      http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      Please reply only to the newsgroup.

      Comment

      • kimiraikkonen

        #4
        Re: &quot;Open with&quot; question

        On Dec 18, 9:12 pm, Mattias Sjögren <mattias.dont.w ant.s...@mvps.o rg>
        wrote:
        How can i make "open with" association to display text with my project
        properly?
        >
        Your application would likely accept the path to the file on the
        command line. You then parse the command line during application
        startup, load the file and display the content in the text box.
        >
        Mattias
        >
        --
        Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/dotnet/|http://www.dotnetinterop.com
        Please reply only to the newsgroup.
        My app is not a console application however, where and what can i add
        this to create a "open with" functionality?

        Comment

        • zacks@construction-imaging.com

          #5
          Re: &quot;Open with&quot; question

          On Dec 18, 2:37 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
          On Dec 18, 9:12 pm, Mattias Sjögren <mattias.dont.w ant.s...@mvps.o rg>
          wrote:
          >
          >How can i make "open with" association to display text with my project
          >properly?
          >
          Your application would likely accept the path to the file on the
          command line. You then parse the command line during application
          startup, load the file and display the content in the text box.
          >
          Mattias
          >
          --
          Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/dotnet/|http://www.dotnetinterop.com
          Please reply only to the newsgroup.
          >
          My app is not a console application however, where and what can i add
          this to create a "open with" functionality?
          If the form's Load event. Check the contents of the
          Environment.Com mandLine. If there is a filename present, open it, read
          the data, and put the data in the textbox's Text property.

          Comment

          • Mattias Sjögren

            #6
            Re: &quot;Open with&quot; question

            >My app is not a console application however, where and what can i add
            >this to create a "open with" functionality?
            The principle is the same in a Windows app. You can still have a
            parameterized Main entry point, or you can use
            System.Environm ent.GetCommandL ineArgs() from anywhere in your code.


            Mattias

            --
            Mattias Sjögren [C# MVP] mattias @ mvps.org
            http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
            Please reply only to the newsgroup.

            Comment

            • kimiraikkonen

              #7
              Re: &quot;Open with&quot; question

              On Dec 18, 9:55 pm, Mattias Sjögren <mattias.dont.w ant.s...@mvps.o rg>
              wrote:
              My app is not a console application however, where and what can i add
              this to create a "open with" functionality?
              >
              The principle is the same in a Windows app. You can still have a
              parameterized Main entry point, or you can use
              System.Environm ent.GetCommandL ineArgs() from anywhere in your code.
              >
              Mattias
              >
              --
              Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/dotnet/|http://www.dotnetinterop.com
              Please reply only to the newsgroup.
              Hi again, could you sample some code and will i put them in form_load
              event?

              Assume, i have a textbox and openfiledialog control and i use
              streamreader to display texts.

              Thanks.

              Comment

              • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                #8
                Re: &quot;Open with&quot; question



                "kimiraikko nen" wrote:
                On Dec 18, 9:55 pm, Mattias Sjögren <mattias.dont.w ant.s...@mvps.o rg>
                wrote:
                >My app is not a console application however, where and what can i add
                >this to create a "open with" functionality?
                The principle is the same in a Windows app. You can still have a
                parameterized Main entry point, or you can use
                System.Environm ent.GetCommandL ineArgs() from anywhere in your code.

                Mattias

                --
                Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/dotnet/|http://www.dotnetinterop.com
                Please reply only to the newsgroup.
                >
                Hi again, could you sample some code and will i put them in form_load
                event?
                >
                Assume, i have a textbox and openfiledialog control and i use
                streamreader to display texts.
                >
                Thanks.
                >
                I believe all you need to do is this:

                Dim arguments As string() = Environment.Get CommandLineArgs ()
                Dim fn as string = arguments(0)

                if (System.IO.File .Exists(fn)) then
                MyTextBox.Text = System.IO.File. ReadAllText(fn)
                endif

                Comment

                • kimiraikkonen

                  #9
                  Re: &quot;Open with&quot; question

                  On Dec 19, 12:46 am, Family Tree Mike
                  <FamilyTreeM... @discussions.mi crosoft.comwrot e:
                  "kimiraikko nen" wrote:
                  On Dec 18, 9:55 pm, Mattias Sjögren <mattias.dont.w ant.s...@mvps.o rg>
                  wrote:
                  My app is not a console application however, where and what can i add
                  this to create a "open with" functionality?
                  >
                  The principle is the same in a Windows app. You can still have a
                  parameterized Main entry point, or you can use
                  System.Environm ent.GetCommandL ineArgs() from anywhere in your code.
                  >
                  Mattias
                  >
                  --
                  Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/dotnet/|http://www.dotnetinterop.com
                  Please reply only to the newsgroup.
                  >
                  Hi again, could you sample some code and will i put them in form_load
                  event?
                  >
                  Assume, i have a textbox and openfiledialog control and i use
                  streamreader to display texts.
                  >
                  Thanks.
                  >
                  I believe all you need to do is this:
                  >
                  Dim arguments As string() = Environment.Get CommandLineArgs ()
                  Dim fn as string = arguments(0)
                  >
                  if (System.IO.File .Exists(fn)) then
                  MyTextBox.Text = System.IO.File. ReadAllText(fn)
                  endif
                  Hi, that doesn't work :-( Only "MZ" is displayed textbox with no sense.

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: &quot;Open with&quot; question

                    "kimiraikko nen" <kimiraikkonen8 5@gmail.comschr ieb:
                    >Dim arguments As string() = Environment.Get CommandLineArgs ()
                    >Dim fn as string = arguments(0)
                    .... should read:

                    \\\
                    If Arguments.Lengt h 1 Then
                    Dim fn As String = Arguments(1)
                    if (System.IO.File .Exists(fn)) then
                    MyTextBox.Text = System.IO.File. ReadAllText(fn)
                    endif
                    End If
                    ///
                    >Hi, that doesn't work :-( Only "MZ" is displayed textbox with
                    no sense.
                    The first argument ('Arguments(0)' ) seems to contain the path to your
                    executable file. 'MZ' are typically the first characters in executable
                    files.

                    --
                    M S Herfried K. Wagner
                    M V P <URL:http://dotnet.mvps.org/>
                    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                    Comment

                    • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                      #11
                      Re: &quot;Open with&quot; question



                      "Herfried K. Wagner [MVP]" wrote:
                      "kimiraikko nen" <kimiraikkonen8 5@gmail.comschr ieb:
                      Dim arguments As string() = Environment.Get CommandLineArgs ()
                      Dim fn as string = arguments(0)
                      >
                      .... should read:
                      >
                      \\\
                      If Arguments.Lengt h 1 Then
                      Dim fn As String = Arguments(1)
                      >
                      if (System.IO.File .Exists(fn)) then
                      MyTextBox.Text = System.IO.File. ReadAllText(fn)
                      endif
                      >
                      End If
                      ///
                      >
                      Hi, that doesn't work :-( Only "MZ" is displayed textbox with
                      no sense.
                      >
                      The first argument ('Arguments(0)' ) seems to contain the path to your
                      executable file. 'MZ' are typically the first characters in executable
                      files.
                      >
                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                      >
                      Thanks Herfried. I wasy typing without a compiler. I believe the command
                      args are starting at index of one as you said.

                      >

                      Comment

                      • kimiraikkonen

                        #12
                        Re: &quot;Open with&quot; question

                        On Dec 19, 3:42 am, Family Tree Mike
                        <FamilyTreeM... @discussions.mi crosoft.comwrot e:
                        "Herfried K. Wagner [MVP]" wrote:
                        >
                        >
                        >
                        "kimiraikko nen" <kimiraikkone.. .@gmail.comschr ieb:
                        >Dim arguments As string() = Environment.Get CommandLineArgs ()
                        >Dim fn as string = arguments(0)
                        >
                        .... should read:
                        >
                        \\\
                        If Arguments.Lengt h 1 Then
                        Dim fn As String = Arguments(1)
                        >
                        if (System.IO.File .Exists(fn)) then
                        MyTextBox.Text = System.IO.File. ReadAllText(fn)
                        endif
                        >
                        End If
                        ///
                        >
                        >Hi, that doesn't work :-( Only "MZ" is displayed textbox with
                        no sense.
                        >
                        The first argument ('Arguments(0)' ) seems to contain the path to your
                        executable file. 'MZ' are typically the first characters in executable
                        files.
                        >
                        --
                        M S Herfried K. Wagner
                        M V P <URL:http://dotnet.mvps.org/>
                        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                        >
                        Thanks Herfried. I wasy typing without a compiler. I believe the command
                        args are starting at index of one as you said.
                        >
                        >
                        Hi there,
                        After trying to figure out where and what the codes are used for i
                        managed to what i was trying to by adding to form_load event:

                        Dim cla As String() = Environment.Get CommandLineArgs ()
                        If cla.Length 1 Then
                        myStreamReader = System.IO.File. OpenText(cla(1) )
                        TextBox1.Text = myStreamReader. ReadToEnd
                        myStreamReader. Dispose()

                        'After text is opened, all the texts come up as selected, thus i added
                        to make them unselected.
                        TextBox1.Select ionStart = 0
                        End If

                        Comment

                        • kimiraikkonen

                          #13
                          Re: &quot;Open with&quot; question

                          On Dec 19, 1:28 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
                          h...@gmx.atwrot e:
                          "kimiraikko nen" <kimiraikkone.. .@gmail.comschr ieb:
                          >
                          Dim arguments As string() = Environment.Get CommandLineArgs ()
                          Dim fn as string = arguments(0)
                          >
                          ... should read:
                          >
                          \\\
                          If Arguments.Lengt h 1 Then
                          Dim fn As String = Arguments(1)
                          >
                          if (System.IO.File .Exists(fn)) then
                          MyTextBox.Text = System.IO.File. ReadAllText(fn)
                          endif
                          >
                          End If
                          ///
                          >
                          Hi, that doesn't work :-( Only "MZ" is displayed textbox with
                          no sense.
                          >
                          The first argument ('Arguments(0)' ) seems to contain the path to your
                          executable file. 'MZ' are typically the first characters in executable
                          files.
                          >
                          --
                          M S Herfried K. Wagner
                          M V P <URL:http://dotnet.mvps.org/>
                          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                          Hi,
                          I want to ask this:

                          Why was i forced to use:

                          If Arguments.Lengt h 1 Then
                          Dim fn As String = Arguments(1)

                          'do stuff

                          end if

                          For example when i want to display the current app's path:

                          Dim cla As String() = Environment.Get CommandLineArgs ()

                          Msgbox(cla(0))

                          shows "exact" path in messagebox, no other extra or unwanted strings
                          like "MZ", so it would be kind of you explaining this issue.

                          Thanks.

                          Comment

                          Working...