在使用ASP.NET写项目中aspx文件和文档声明对于浏览器兼容性有很大影,我手头就有一个项目原来是在IE6下跑的没有问题,
可是换成IE8后就有很多问题,搞了半天发现只要将文档的头声明更改一下就可以了,将原来的声明如下:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
换成如下,
- <!DOCTYPE html>
- <html>
样式的大部分问题就可以搞定,
换吧使用Ctrl+H在VS2008一跑全部项目替换,结果死了,文件太多600多个aspx文件,无奈自己写了一个小工具来完成这个功能,
感觉挺实用的就放出来!
老鸟路过!
界面:
代码:
- private void button1_Click(object sender, EventArgs e)
- {
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
- {
- txtpath.Text = folderBrowserDialog1.SelectedPath;
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- //验证
- errorProvider1.SetError(txtpath, "");
- if (txtpath.Text.Length == 0)
- {
- errorProvider1.SetError(txtpath, "不为空!");
- txtpath.Focus();
- return;
- }
- errorProvider1.SetError(txtExt, "");
- if (txtpath.Text.Length == 0)
- {
- errorProvider1.SetError(txtExt, "不为空!");
- txtExt.Focus();
- return;
- }
- n = 0;
- //处理文件
- GoProcFile(txtpath.Text);
- this.Text = "完成!共处理"+n+"个文件!";
- n = 0;
- }
- int n = 0;
- void GoProcFile(string path)
- {
- foreach (var f in Directory.GetFiles(path, txtExt.Text))
- {
- n++;
- //替换文件
- ReplaceFile(f);
- }
- //如果处理子文件夹
- if (checkBox1.Checked)
- {
- foreach (var dir in Directory.GetDirectories(path))
- {
- GoProcFile(dir);
- }
- }
- }
- private void ReplaceFile(string f)
- {
- StreamReader sr = new StreamReader(f, Encoding.Default);
- StringBuilder sb = new StringBuilder(sr.ReadToEnd());
- sr.Close();
- sb = sb.Replace(txt1.Text, txt2.Text);
- StreamWriter sw = new StreamWriter(f, false, Encoding.Default);
- sw.Write(sb.ToString());
- sw.Close();
- this.Text = f;
- Thread.Sleep(1);
- }
程序及源代码已放在我的下载下了:http://lijun7788.download.csdn.net/