Results 1 to 4 of 4

Thread: [RESOLVED] Help with opening Link

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Help with opening Link

    hi guys help please. Currently, I have this code
    Code:
                System.Diagnostics.Process.Start(EventAttachmentLink);
    to open a link, but it opens the link in one of my opened Internet Browser. My question is, is it posible to open a particular link in a new Internet Browser Window? Thanks in advance!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with opening Link

    That is a function of the browser itself. The browser will normally have an option to change that default behaviour. If you want to override the default behaviour without adjusting the browser settings then you need to specify the browser itself as the file name and the URL as an argument, e.g.
    C# Code:
    1. Process.Start("iexplore", EventAttachmentLink);
    The problem with that is that you won't be using the default browser in many cases. I believe that Windows stores information about browsers and which one is the default in the registry, so you could get the correct path from there.

    I'm fairly sure that Shaggy Hiker or kleinma tackled this issue some time ago and put something in the Codebank too. I don't remember the specifics though. It was probably the VB.NET Codebank but conversion would be simple.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help with opening Link

    OK..I'll give it a try..Thanks again JM.

  4. #4

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help with opening Link

    Ok..I come up with the code below.
    Code:
                //Get path of the default internet explorer
                string defaultBrowser = null;
                //HKEY_CLASSES_ROOT\https\shell\open\command is the Registry path where you can get the default Internet Explorer            
                RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command");
                if (regKey != null)
                {
                    //The value name in my registry is blank ("") or (default)
                    //but it contains value "C:\Program Files\Internet Explorer\iexplore.exe" -nohome
                    defaultBrowser = (string)regKey.GetValue("");
    
                    //Since I only need the path (C:\Program Files\Internet Explorer\iexplore.exe)
                    //I will remove any charcater before the first '"' 
                    defaultBrowser = defaultBrowser.Remove(0, defaultBrowser.IndexOf("\"") + 1);
    
                    //And remove any character after the second '"'
                    defaultBrowser = defaultBrowser.Remove(defaultBrowser.IndexOf("\""));
    
                    //Remove any white space character
                    defaultBrowser.Trim();
                }
    
    //Open Link
                System.Diagnostics.Process pOpenLink = new System.Diagnostics.Process();
                pOpenLink.StartInfo.CreateNoWindow = true;
                pOpenLink.StartInfo.FileName = defaultBrowser;
                pOpenLink.StartInfo.Arguments = EventAttachmentLink;
                pOpenLink.Start();
    Thanks a lot JM!
    Last edited by daimous; Jul 31st, 2007 at 12:20 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width