软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 网络编程 > ASP教程 > C#获取我的收藏网站及打开URL

C#获取我的收藏网站及打开URL

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

using System.Runtime.InteropServices;

using IWshRuntimeLibrary;

烈火网(liehuo.net)提示:点击新窗口预览!

以下为引用的内容:
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);
   }
}

    相关阅读
    栏目导航
    推荐软件