欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Asp.NET生成各种网页快捷方式的代码(桌面url快捷方式,收藏夹/开始菜单快捷方式)

程序员文章站 2024-03-06 20:11:50
复制代码 代码如下: using system; using system.data; using system.configuration; using system.c...
复制代码 代码如下:

using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
public partial class createshortcut : system.web.ui.page
{
  protected void page_load(object sender, eventargs e)
{
}
/// <summary>
/// 创建快捷方式
/// </summary>
/// <param name="title">标题</param>
/// <param name="url">url地址</param>
private void createshortcut(string title, string url)
{
string strfavoritefolder;
// “收藏夹”中 创建 ie 快捷方式
strfavoritefolder = system.environment.getfolderpath(environment.specialfolder.favorites);
createshortcutfile(title, url, strfavoritefolder);
// “ 桌面 ”中 创建 ie 快捷方式
strfavoritefolder = system.environment.getfolderpath(environment.specialfolder.desktop);
createshortcutfile(title, url, strfavoritefolder);
// “ 链接 ”中 创建 ie 快捷方式
strfavoritefolder = system.environment.getfolderpath(environment.specialfolder.favorites) + "\\链接";
createshortcutfile(title, url, strfavoritefolder);
//「开始」菜单中 创建 ie 快捷方式
strfavoritefolder = system.environment.getfolderpath(environment.specialfolder.startmenu);
createshortcutfile(title, url, strfavoritefolder);
}
/// <summary>
/// 创建快捷方式
/// </summary>
/// <param name="title">标题</param>
/// <param name="url">url地址</param>
/// <param name="specialfolder">特殊文件夹</param>
private void createshortcutfile(string title, string url, string specialfolder)
{
// create shortcut file, based on title
system.io.streamwriter objwriter = system.io.file.createtext(specialfolder + "\\" + title + ".url");
// write url to file
objwriter.writeline("[internetshortcut]");
objwriter.writeline("url=" + url);
// close file
objwriter.close();
}
private void btnshortcut_click(object sender, system.eventargs e)
{
createshortcut("", //www.jb51.net);
}
}