C#如何创建快捷方式和添加网页到收藏夹
为了方便大家的学习,下面是小编整理的关于C#如何创建快捷方式和添加网页到收藏夹的.方法,欢迎参考!
一、C#创建快捷方式
要创建快捷方式须引用,引用方式为:对项目添加引用——>选择COM组件——>选择"Windows Script Host Object Model"确定,则添加成功!接下来就是编码:
///
/// 生成快捷方式
///
/// 原目标位置
/// /// 保存快捷方式的位置
protected void CreateShortcuts(String targetPath, String savePath,String saveName)
{
Shell shell_class = new Shell_ClassClass();
Shortcut shortcut = null;
if (!ts(targetPath))
return;
if (!Directory(savePath))
teDirectory(savePath);
try
{
shortcut = shell_teShortcut(savePath + @"/" + saveName + "") as Shortcut;
etPath = targetPath;
();
("创佳快捷方式成功!");
}
catch (Exception ex)
{
("创佳快捷方式失败!");
}
}
以上是C#里面调用相应的方法创建快捷方式的方法;接下来要讲的是C#里面将一个网页添加到收藏夹里面,其实将网页添加到收藏夹里的实质是将给定的网页生成一个快捷方式并放在收藏夹对应的电脑的物理文件夹里面即可。
二、将网页添加到收藏夹
首先,像第一步一样引用相应的dll
///
/// 添加收藏夹
///
/// 对应的网页的url
/// 保存的名称
/// 文件夹名称
protected void AddToFavorites(String url, String saveName, String folderName)
{
WebRequest request = (WebRequest)te(new Uri(url));
od = "GET";
out = 10000;
try
{
WebResponse response = (WebResponse)esponse();
if (usCode == )
{
//获取当前用户的收藏夹的物理文件夹位置
String favoritesPath = olderPath(rites);
String savePath = favoritesPath;
if (!llOrEmpty(folderName))
{
savePath += @"/" + folderName;
if (!ts(savePath))
teDirectory(savePath);
}
hell shell_class = new hellClass();
Shortcut shortcut = null;
try
{
shortcut = shell_teShortcut(favoritesPath + @"/" + saveName + "") as Shortcut;
etPath = url;
();
("添加成功");
}
catch (Exception ex)
{
("添加失败");
}
}
else
{
("请求失败");
}
}
catch (Exception ex)
{
(age);
}
}