C#如何創建快捷方式和添加網頁到收藏夾

來源:文萃谷 1.76W

為了方便大家的學習,下面是小編整理的關於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);

}

}

熱門標籤