Results 1 to 4 of 4

Thread: Open a text file with double click

  1. #1
    Reyn's Avatar
    Reyn is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Dec 2008
    Posts
    14
    Reputation
    57

    Open a text file with double click

    This thread contains information on how to do this. However, I was wondering if the origrinal, or anyone else for that matter, could explain what the openFile is in his code. I am guessing it has to do with the System.IO namespace, but I am unsure of what he did, and I am trying to get my application to open text files on an open command.

    If anyone could provide another way that was better i would appreciate that too.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,209
    Reputation
    2369
    Code:
    Me.TextBox1.Text = My.Computer.FileSystem.ReadAllText(filepath)
    filepath variable here contains the file path string.

  3. #3
    Reyn's Avatar
    Reyn is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Dec 2008
    Posts
    14
    Reputation
    57
    Thanks. I'll have to give this a try. However, i do have a question. How do i get the filepath put into the variable? the program wont be active yet, until the file is opened. how do i take that files path and put it into the variable?

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,209
    Reputation
    2369
    Actually, you don't need to use a variable at all, I just used a variable to show you how to call the ReadAllText method. The point is, the ReadAllText method takes a parameter of type string that should contain a file path. Since one or more of the strings in the array of command line arguments is the file path, you just pass those as parameters.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking