实现效果:
知识运用:
Environment类的GetFolderPat方法
StreamWriter类的WriterLine方法
实现代码:
private void button1_Click(object sender, EventArgs e) { try { string favoriterFolder=Environment.GetFolderPath(Environment.SpecialFolder.Favorites); StreamWriter sw = File.CreateText(favoriterFolder+"\\"+textBox2.Text+textBox1.Text+".url"); sw.WriteLine("[InternetShortcut]"); sw.WriteLine("URL="+textBox1.Text); sw.Close(); MessageBox.Show("添加成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }