C#获取我的收藏网站及打开URL
作者:C/S框架网  发布日期:2011/07/16 00:30:52
C#获取我的收藏网站及打开URL


首先添加以下引用:COMWindows Script Host Object Model

using System.Runtime.InteropServices;

using IWshRuntimeLibrary;

private void button1_Click(object sender, EventArgs e)
{
   //获取我的收藏网址.
   this.BuildTree(this.treeView1);
}

private void treeView1_DoubleClick(object sender, EventArgs e)
{
   if (treeView1.SelectedNode != null)
   {
      string file = treeView1.SelectedNode.Tag.ToString();
      if (file.Trim() != "") //如果有url地址,打开网页
      {
         IWshShell_Class shell = new IWshShell_ClassClass();
         IWshURLShortcut _shortcut = shell.CreateShortcut(file) as IWshURLShortcut;
         webBrowser1.Navigate(_shortcut.TargetPath);
      }
   }
}

public void BuildTree(TreeView tv)
{
   string path = System.Environment.SystemDirectory;
   path = path.Substring(0, path.IndexOf("\\") + 1);
   path = path + @"Documents and Settings\" + System.Environment.UserName + "\\Favorites";
   DirectoryInfo dir = new DirectoryInfo(path);
   
   foreach (FileInfo file in dir.GetFiles())
   {
      TreeNode node = new TreeNode();
      node.Text = file.Name; //文件名
      node.Tag = file.FullName; //文件路径.
      tv.Nodes.Add(node);
   }
}


 



C/S框架网|原创精神.创造价值.打造精品


扫一扫加作者微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务


点击下载附件 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇