<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. C#如何創建快捷方式和添加網頁到收藏夾

    時間:2024-09-19 07:04:17 ACCP培訓 我要投稿
    • 相關推薦

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

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

      一、C#創建快捷方式

      要創建快捷方式須引用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("創佳快捷方式成功!");

      }

      catch (Exception ex)

      {

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

      }

      }

      以上是C#里面調用相應的方法創建快捷方式的方法;接下來要講的是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#如何創建快捷方式和添加網頁到收藏夾】相關文章:

    如何識別和防御Web網頁木馬09-11

    word如何添加標題樣式06-26

    PPT如何添加超鏈接09-28

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

    c#和javascript函數相互調用示例10-16

    如何在模板之間添加素材07-16

    ppt中如何添加超鏈接09-05

    C# AutoResetEvent的使用10-29

    會聲會影如何添加遮罩07-08

    linux如何給文件或目錄添加apache權限11-03

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人