locked
how to add the path of an html file in the string of codes RRS feed

  • Question

  • hey I  have an editor that saves text files and html files. I want to open my html file in Internet Explorer.  

    The code for opening the IE and the file is below

    Shell("C:\Program Files\Internet Explorer\iexplore.exe C:\abc.html")
    

    The code works but the problem is that I want to get the path of the file in a textbox named txtpath. Can you figure out how to concatenate the path in the line of code above. From the code above, how can I put the C:\abc.html(example path) in the code.. Can you help me to fix this.. hope you can help me

    Monday, August 1, 2011 10:26 AM

Answers

  • Don't use Shell.
    http://msdn.microsoft.com/en-us/library/h6ak8zt5(v=VS.90).aspx

    To use a control property in place of a portion of that string literal, the expression looks like this:

    "C:\Program Files\Internet Explorer\iexplore.exe " & txtPath.Text

    But using the correct method does not require one large string - it takes two separate strings.  So your code becomes:
    Process.Start("C:\Program Files\Internet Explorer\iexplore.exe", txtPath.Text)

    • Proposed as answer by Blackwood Monday, August 1, 2011 12:35 PM
    • Marked as answer by Mike Feng Monday, August 8, 2011 2:00 PM
    Monday, August 1, 2011 10:44 AM

All replies

  • Don't use Shell.
    http://msdn.microsoft.com/en-us/library/h6ak8zt5(v=VS.90).aspx

    To use a control property in place of a portion of that string literal, the expression looks like this:

    "C:\Program Files\Internet Explorer\iexplore.exe " & txtPath.Text

    But using the correct method does not require one large string - it takes two separate strings.  So your code becomes:
    Process.Start("C:\Program Files\Internet Explorer\iexplore.exe", txtPath.Text)

    • Proposed as answer by Blackwood Monday, August 1, 2011 12:35 PM
    • Marked as answer by Mike Feng Monday, August 8, 2011 2:00 PM
    Monday, August 1, 2011 10:44 AM
  • do i use the Process.Start("C:\Program Files\Internet Explorer\iexplore.exe", txtPath.Text) ??

    is it the only code?

    Monday, August 1, 2011 10:46 AM
  • do i use the Process.Start("C:\Program Files\Internet Explorer\iexplore.exe", txtPath.Text) ??

    is it the only code?


    Yes. Or if you have already checked that txtPath.Text contains the path to an HTML file. you could code

    Process.Start(txtPath.Text)
    

    which would open the file in the application associated with .html files, which should be the user's default browser (Firefox and Chrome users may not like it if you force them to use Internet Explorer).
    Monday, August 1, 2011 12:41 PM
  • There are many variations on that code which are possible, but if all you are trying to do is to open Internet Explorer at a particular URL, that is all you need.

    A common variation is to instead open the user's default web browser at a particular URL.  This would be:
    Process.Start(txtPath.Text)

    How well those commands work depends on whether or not the contents of txtPath.Text is a valid, accessible address.

    Monday, August 1, 2011 10:17 PM