1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 public partial class CreateShortcut : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 }
17
18 /// <summary>
19 /// 建立捷徑
20 /// </summary>
21 /// <param name="Title">標題</param>
22 /// <param name="URL">URL地址</param>
23 private void CreateShortcut(string Title, string URL)
24 {
25 string strFavoriteFolder;
26
27 // “收藏夾”中 建立 IE 捷徑
28 strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
29 CreateShortcutFile(Title, URL, strFavoriteFolder);
30
31 // “ 案頭 ”中 建立 IE 捷徑
32 strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
33 CreateShortcutFile(Title, URL, strFavoriteFolder);
34
35 // “ 連結 ”中 建立 IE 捷徑
36 strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\\連結";
37 CreateShortcutFile(Title, URL, strFavoriteFolder);
38
39 //「開始」菜單中 建立 IE 捷徑
40 strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
41 CreateShortcutFile(Title, URL, strFavoriteFolder);
42
43 }
44
45 /// <summary>
46 /// 建立捷徑
47 /// </summary>
48 /// <param name="Title">標題</param>
49 /// <param name="URL">URL地址</param>
50 /// <param name="SpecialFolder">特殊檔案夾</param>
51 private void CreateShortcutFile(string Title, string URL, string SpecialFolder)
52 {
53 // Create shortcut file, based on Title
54 System.IO.StreamWriter objWriter = System.IO.File.CreateText(SpecialFolder + "\\" + Title + ".url");
55 // Write URL to file
56 objWriter.WriteLine("[InternetShortcut]");
57 objWriter.WriteLine("URL=" + URL);
58 // Close file
59 objWriter.Close();
60 }
61
62 private void btnShortcut_Click(object sender, System.EventArgs e)
63 {
64 CreateShortcut("IT鳥的專欄 - 部落格圓", http://www.cnblogs.com/ITniao/);
65 }
66 }