亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

ACCP培訓

C#如何創(chuàng)建快捷方式和添加網頁到收藏夾

時間:2024-10-28 23:43:53 ACCP培訓 我要投稿
  • 相關推薦

C#如何創(chuàng)建快捷方式和添加網頁到收藏夾

  為了方便大家的學習,下面是小編整理的關于C#如何創(chuàng)建快捷方式和添加網頁到收藏夾的方法,歡迎參考!

  一、C#創(chuàng)建快捷方式

  要創(chuàng)建快捷方式須引用IWshRuntimeLibrary.dll,引用方式為:對項目添加引用——>選擇COM組件——>選擇"Windows Script Host Object Model"確定,則添加成功!接下來就是編碼:

  ///

  /// 生成快捷方式

  ///

  /// 原目標位置

  /// /// 保存快捷方式的位置

  protected void CreateShortcuts(String targetPath, String savePath,String saveName)

  {

  IWshRuntimeLibrary.IWshShell shell_class = new IWshRuntimeLibrary.IWshShell_ClassClass();

  IWshRuntimeLibrary.IWshShortcut shortcut = null;

  if (!Directory.Exists(targetPath))

  return;

  if (!Directory(savePath))

  Directory.CreateDirectory(savePath);

  try

  {

  shortcut = shell_class.CreateShortcut(savePath + @"/" + saveName + ".lnk") as IWshRuntimeLibrary.IWshShortcut;

  shortcut.TargetPath = targetPath;

  shortcut.Save();

  MessageBox.Show("創(chuàng)佳快捷方式成功!");

  }

  catch (Exception ex)

  {

  MessageBox.Show("創(chuàng)佳快捷方式失敗!");

  }

  }

  以上是C#里面調用相應的方法創(chuàng)建快捷方式的方法;接下來要講的是C#里面將一個網頁添加到收藏夾里面,其實將網頁添加到收藏夾里的實質是將給定的網頁生成一個快捷方式并放在收藏夾對應的電腦的物理文件夾里面即可。

  二、將網頁添加到收藏夾

  首先,像第一步一樣引用相應的dll

  ///

  /// 添加收藏夾

  ///

  /// 對應的網頁的url

  /// 保存的名稱

  /// 文件夾名稱

  protected void AddToFavorites(String url, String saveName, String folderName)

  {

  System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(new Uri(url));

  request.Method = "GET";

  request.Timeout = 10000;

  try

  {

  System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

  if (response.StatusCode == System.Net.HttpStatusCode.OK)

  {

  //獲取當前用戶的收藏夾的物理文件夾位置

  String favoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

  String savePath = favoritesPath;

  if (!String.IsNullOrEmpty(folderName))

  {

  savePath += @"/" + folderName;

  if (!Directory.Exists(savePath))

  Directory.CreateDirectory(savePath);

  }

  IWshRuntimeLibrary.WshShell shell_class = new IWshRuntimeLibrary.WshShellClass();

  IWshRuntimeLibrary.IWshShortcut shortcut = null;

  try

  {

  shortcut = shell_class.CreateShortcut(favoritesPath + @"/" + saveName + ".lnk") as IWshRuntimeLibrary.IWshShortcut;

  shortcut.TargetPath = url;

  shortcut.Save();

  MessageBox.Show("添加成功");

  }

  catch (Exception ex)

  {

  MessageBox.Show("添加失敗");

  }

  }

  else

  {

  MessageBox.Show("請求失敗");

  }

  }

  catch (Exception ex)

  {

  MessageBox.Show(ex.Message);

  }

  }

【C#如何創(chuàng)建快捷方式和添加網頁到收藏夾】相關文章:

在word 2003文檔添加收藏夾的方法07-19

如何識別和防御Web網頁木馬08-25

如何用C#制作氣泡屏幕保護07-19

如何添加用戶對網站的黏度?05-27

PPT如何添加超鏈接10-16

word如何添加標題樣式07-30

c#和javascript函數(shù)相互調用示例08-23

如何添加網絡打印機09-24

網站頁面中如何添加鏈接?10-22

如何在模板之間添加素材10-27