📄 createhtml.cs
字号:
private void btnTransferGb_Click(object sender, EventArgs e)
{
string strType = txbType.Text.Trim();
string strFolder = txbFolder.Text.Trim();
if (strType.Length == 0)
{
MessageBox.Show("请输入文件类型");
return;
}
else if (strFolder.Length == 0)
{
MessageBox.Show("请选择文件夹");
return;
}
else if (!Directory.Exists(strFolder))
{
MessageBox.Show("文件夹不存在");
return;
}
else if (string.IsNullOrEmpty(Path.GetDirectoryName(strFolder)))
{
MessageBox.Show("不能选择根目录");
return;
}
else
{
strExtName = strType.Split(',');
this.txbMsg.Text = string.Empty;
this.txbMsg.Text += "\n清楚格式";
this.txbMsg.Text += "\n开始处理......";
try
{
DirectoryInfo info3 = new DirectoryInfo(strFolder);
foreach (FileSystemInfo info4 in info3.GetFileSystemInfos())
{
if (info4 is FileInfo)
{
FileInfo info = (FileInfo)info4;
string str = info.DirectoryName + @"\" + info.Name;
string extension = info.Extension;
for (int i = 0; i < this.strExtName.Length; i++)
{
if (this.strExtName[i] == extension.ToLower())
{
this.UTFTOGB2312(info.DirectoryName + @"\", info.Name, extension);
}
}
}
else
{
DirectoryInfo info2 = (DirectoryInfo)info4;
this.getUTFTOGB2312AllFile(info2.FullName + @"\");
}
}
}
catch (Exception ex)
{
MessageBox.Show(this, "Error Message:" + ex.Message);
}
this.txbMsg.Text += "\n处理完成";
}
}
private void UTFTOGB2312(string txtFileDir, string txtFileName, string txtFileType)
{
StringBuilder htmltext = new StringBuilder();
string strFile = txtFileDir + txtFileName;
using (StreamReader reader = new StreamReader(strFile, System.Text.Encoding.GetEncoding("utf-8")))
{
while (!reader.EndOfStream)
{
string str5 = reader.ReadLine();
if (str5.Trim().Length > 0)
{
htmltext.AppendLine(str5);
}
}
reader.Close();
}
this.txbMsg.Text += "\n" + strFile;
using (StreamWriter sw = new StreamWriter(strFile, false, System.Text.Encoding.GetEncoding("gb2312")))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
}
}
protected void getUTFTOGB2312AllFile(string txtDirPath)
{
DirectoryInfo info3 = new DirectoryInfo(txtDirPath);
foreach (FileSystemInfo info4 in info3.GetFileSystemInfos())
{
if (info4 is FileInfo)
{
FileInfo info = (FileInfo)info4;
string str = info.DirectoryName + @"\" + info.Name;
string extension = info.Extension;
for (int i = 0; i < this.strExtName.Length; i++)
{
if (this.strExtName[i] == extension.ToLower())
{
this.UTFTOGB2312(info.DirectoryName + @"\", info.Name, extension);
}
}
}
else
{
DirectoryInfo info2 = (DirectoryInfo)info4;
this.getUTFTOGB2312AllFile(info2.FullName + @"\");
}
}
}
private void GB2312TOUTF(string txtFileDir, string txtFileName, string txtFileType)
{
StringBuilder htmltext = new StringBuilder();
string strFile = txtFileDir + txtFileName;
using (StreamReader reader = new StreamReader(strFile, System.Text.Encoding.GetEncoding("gb2312")))
{
while (!reader.EndOfStream)
{
string str5 = reader.ReadLine();
if (str5.Trim().Length > 0)
{
htmltext.AppendLine(str5);
}
}
reader.Close();
}
this.txbMsg.Text += "\n" + strFile;
using (StreamWriter sw = new StreamWriter(strFile, false, System.Text.Encoding.GetEncoding("utf-8")))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
}
}
protected void getGB2312TOUTFAllFile(string txtDirPath)
{
DirectoryInfo info3 = new DirectoryInfo(txtDirPath);
foreach (FileSystemInfo info4 in info3.GetFileSystemInfos())
{
if (info4 is FileInfo)
{
FileInfo info = (FileInfo)info4;
string str = info.DirectoryName + @"\" + info.Name;
string extension = info.Extension;
for (int i = 0; i < this.strExtName.Length; i++)
{
if (this.strExtName[i] == extension.ToLower())
{
this.GB2312TOUTF(info.DirectoryName + @"\", info.Name, extension);
}
}
}
else
{
DirectoryInfo info2 = (DirectoryInfo)info4;
this.getGB2312TOUTFAllFile(info2.FullName + @"\");
}
}
}
private void btnTransferUtf_Click(object sender, EventArgs e)
{
string strType = txbType.Text.Trim();
string strFolder = txbFolder.Text.Trim();
if (strType.Length == 0)
{
MessageBox.Show("请输入文件类型");
return;
}
else if (strFolder.Length == 0)
{
MessageBox.Show("请选择文件夹");
return;
}
else if (!Directory.Exists(strFolder))
{
MessageBox.Show("文件夹不存在");
return;
}
else if (string.IsNullOrEmpty(Path.GetDirectoryName(strFolder)))
{
MessageBox.Show("不能选择根目录");
return;
}
else
{
strExtName = strType.Split(',');
this.txbMsg.Text = string.Empty;
this.txbMsg.Text += "\nGB2312转UTF-8";
this.txbMsg.Text += "\n开始处理......";
try
{
DirectoryInfo info3 = new DirectoryInfo(strFolder);
foreach (FileSystemInfo info4 in info3.GetFileSystemInfos())
{
if (info4 is FileInfo)
{
FileInfo info = (FileInfo)info4;
string str = info.DirectoryName + @"\" + info.Name;
string extension = info.Extension;
for (int i = 0; i < this.strExtName.Length; i++)
{
if (this.strExtName[i] == extension.ToLower())
{
this.UTFTOGB2312(info.DirectoryName + @"\", info.Name, extension);
}
}
}
else
{
DirectoryInfo info2 = (DirectoryInfo)info4;
this.getGB2312TOUTFAllFile(info2.FullName + @"\");
}
}
}
catch (Exception ex)
{
MessageBox.Show(this, "Error Message:" + ex.Message);
}
this.txbMsg.Text += "\n处理完成";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -