C#调用浏览器的功能实现浅析

C#调用浏览器是如何实现的呢?我们在实际的开发过程中会遇到这样的需求,那么来实现C#调用浏览器会用到什么方法呢?这里向你介绍了调用IE以及默认浏览器的具体操作。

C#调用浏览器之调用IE:

 
 
 
  1. System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); 
  2. myProcess.StartInfo.FileName = "iexplore.exe";
  3. myProcess.StartInfo.Arguments = " http://www.net0and1.com/";
  4. myProcess.Start();

C#调用浏览器之调用默认浏览器:

 
 
 
  1. string target= "http://www.net0and1.com"; 
  2. //Use no more than one assignment when you test this code.
  3. //string target = "ftp://ftp.microsoft.com"; 
  4. //string target = "C:\\Program Files\\Microsoft Visual Studio\\INSTALL.HTM";
  5. try
  6. {
  7.  System.Diagnostics.Process.Start(target);
  8. }
  9. catch
  10. (
  11.  System.ComponentModel.Win32Exception noBrowser)
  12. {
  13.  if (noBrowser.ErrorCode==-2147467259)
  14.   MessageBox.Show(noBrowser.Message);
  15. }
  16. catch (System.Exception other)
  17. {
  18.   MessageBox.Show(other.Message);
  19. }

C#调用浏览器的操作就向你介绍到这里,希望对你了解和学习使用C#调用浏览器有所帮助。


分享文章:C#调用浏览器的功能实现浅析
文章转载:http://gydahua.com/article/dhpeipg.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流