webbrowser沒有這功能,只能自己寫。
要創建快捷方式需要用到IWshRuntimeLibrary命名空間,在這裡我們要USING一下。並在引用裡添加一個COM,windows script host object model。
codeprivate void CreateShortCut()
{
string mysite = "http://" + iis + "/path/defaut.aspx";
//創建Windows Script Host Shell類
IWshRuntimeLibrary.IWshShell_Class shell = new IWshRuntimeLibrary.IWshShell_ClassClass();
if (this.Context.Parameters["ckFavorites"] == "1")
{
string fav = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites) + "\\××××××××.url";
//定義快捷方式文件
IWshRuntimeLibrary.IWshURLShortcut shortcut = shell.CreateShortcut(fav) as IWshRuntimeLibrary.IWshURLShortcut;
shortcut.TargetPath = mysite;
//保存快捷方式
shortcut.Save();
}
if (this.Context.Parameters["ckDesktop"] == "1")
{
string dsk = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\××××××××.url";
IWshRuntimeLibrary.IWshURLShortcut shortcut = shell.CreateShortcut(dsk) as IWshRuntimeLibrary.IWshURLShortcut;
shortcut.TargetPath = mysite;
shortcut.Save();
}
}