C# 清理Cookies文件实例代码
来源:
发布时间:2010/9/27
浏览次数:1109
C# 清理Cookies文件实例代码如下:
1.using System;
2.using System.IO;
3.using System.Windows.Forms;
4.
5.namespace WinFormTemp
6.{
7. public partial class FormTemp : Form
8. {
9. public FormTemp()
10. {
11. InitializeComponent();
12. this.HelpButton = true;
13. this.MaximizeBox = false;
14. this.MinimizeBox = false;
15. this.AutoSizeMode = AutoSizeMode.GrowAndShrink; // 禁用手动调整大小。
16. this.SizeGripStyle = SizeGripStyle.Hide; // 隐藏调整大小手柄。
17. this.StartPosition = FormStartPosition.CenterScreen; // 在桌面居中显示。
18. }
19.
20. protected override void OnLoad(EventArgs e)
21. {
22. base.OnLoad(e);
23. DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
24. foreach (FileInfo info in dir.GetFiles("*.txt"))
25. {
26. info.Delete();
27. }
28. System.Diagnostics.Process.Start(dir.FullName);
29. }
30.
31. protected override void OnHelpButtonClicked(System.ComponentModel.CancelEventArgs e)
32. {
33. base.OnHelpButtonClicked(e);
34. e.Cancel = true;
35. FileInfo info = new FileInfo("Clear.bat");
36. if (info.Exists)
37. info.Attributes = FileAttributes.Normal;
38. using (StreamWriter sw = info.CreateText())
39. {
40. sw.WriteLine("@echo off");
41. sw.Write(@"del /f /s /q ""{0}""", Environment.GetFolderPath(Environment.SpecialFolder.Cookies));
42. }
43. System.Diagnostics.Process.Start(info.DirectoryName);
44. }
45. }
46.}