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.111cn.net/);
65 }
66 }