Abbas Hamza

Abbas Hamza

  • NA
  • 100
  • 51.5k

how to use switch statement to navigate between url c#

Apr 12 2016 7:09 AM
i have this method which will take 1 url :
  1. public static void LaunchSite(Uri sitUrl)  
  2.        {  
  3.             
  4.            SHDocVw.ShellWindows w = new SHDocVw.ShellWindows();  
  5.            bool found = false;  
  6.            foreach (SHDocVw.ShellBrowserWindow item in w)  
  7.            {  
  8.                var doc = item.LocationURL;  
  9.                if (!string.IsNullOrEmpty(doc))  
  10.                    if (doc == sitUrl.AbsoluteUri)  
  11.                    {  
  12.                        found = true;  
  13.                        break;  
  14.                    }  
  15.            }  
  16.            if (!found)  
  17.                Process.Start(sitUrl.AbsoluteUri);  
  18.        }  
button event handler looks like this
 
 
  1. private void btnSubs_Click(object sender, RoutedEventArgs e)  
  2.       {  
  3.           //StartProcess.webSit();  
  4.           Uri oxfArt = new Uri(@"http://www.oxfordartonline.com/subscriber/");  
  5.           Uri theoryTst = new Uri("http://theorytestpro.co.uk/");  
  6.           string webAddress = oxfArt.OriginalString;  
  7.           switch (webAddress)  
  8.           {  
  9.               case "http://www.oxfordartonline.com/subscriber/":  
  10.                StartProcess.LaunchSite(oxfArt);  
  11.                   break;  
  12.               case "http://theorytestpro.co.uk/":  
  13.                   StartProcess.LaunchSite(theoryTst);  
  14.                   break;  
  15.               default:  
  16.                   break;  
  17.           }  
  18.            
  19.   
  20.       }  
 the button event handler will handle multiple buttons so depending on which button clicked need to determine which Uri need to be launched using switch statement. thank you

Answers (4)