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);
}
}

转载请注明:代码家园 » C#获取我的收藏网站及打开URL

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)