惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Scott Helme
Scott Helme
Webroot Blog
Webroot Blog
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News | PayPal Newsroom
Help Net Security
Help Net Security
The Hacker News
The Hacker News
H
Heimdal Security Blog
O
OpenAI News
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 叶小钗
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security Affairs
P
Proofpoint News Feed
S
Secure Thoughts
腾讯CDC
Google DeepMind News
Google DeepMind News
量子位
罗磊的独立博客

博客园 - 9527的晃悠人生

(转)使用Visual Studio.net调试javascript最方便的方法 jsoho.com介绍 测试 学习计划 简单权限验证的方法 用log4net快速构建asp.net 异常日志 查找某些记录中重复的记录 竞猜系统设计文档 足球联赛竞猜管理 遍厉目录下文件和子目录 自定义下载文件名 调试断点的条件设置 Asp.net 中 页面无刷新的做法 内容服务中的大文本处理。 关于Asp的性能优化 Insert 一个字段类型是自动增量的,又要写入变量 第三方的数据控件、分页控件 关于网络文学站的相关事宜 利用PD进行数据库建模
用C#实现将html文件转换为chm文件
9527的晃悠人生 · 2004-06-15 · via 博客园 - 9527的晃悠人生

这些天因为工作需要,要将一些html文件转换为chm文件,当然是需要和程序结合在一起。
后来找到NDoc,里头有一段代码是相关的,于是开始分析代码,写完之后,总结:主要是利用微软的hhc.exe来编译html文件,程序需要将具体的数据写入hhp和hhc文件。
主要代码如下:
  public void CompileProject()
  {
   Process helpCompileProcess = new Process();  //创建新的进程,NDOC采用Process启动HHC.EXE来Compile一个CHM文件

   try
   {
    ////判断文件是否存在并不被占用
    try
    {
     string path = _chmFile;  //chm生成路径

     if (File.Exists(path))
     {
      File.Delete(path);
     }
    }
    catch
    {
     throw new Exception("文件被打开!");
    }

    ProcessStartInfo processStartInfo = new ProcessStartInfo();
    processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    processStartInfo.FileName = hhcFile;  //调入HHC.EXE文件 
    processStartInfo.Arguments = "\"" + Path.GetFullPath(GetPathToProjectFile()) + "\"";//获取空的HHP文件

    helpCompileProcess.StartInfo = processStartInfo;

    //开始生成....
    helpCompileProcess.Start();

    helpCompileProcess.WaitForExit(); //组件无限期地等待关联进程退出

    if (helpCompileProcess.ExitCode == 0)
    {
     MessageBox.Show(new Exception().Message );
    }

   }
   finally
   {
     helpCompileProcess.Close();
   }
  }
  public void OpenProjectFile()
  {
   FileStream fs = new FileStream(GetPathToProjectFile(),FileMode.Create);
   streamHtmlHelp = new System.IO.StreamWriter(fs,System.Text.Encoding.GetEncoding("GB18030"));
   streamHtmlHelp.WriteLine("[FILES]");
  }
  public void AddFileToProject(string filename)
  {
   streamHtmlHelp.WriteLine(filename);
  }
  public void CloseProjectFile(string title)
  {
   streamHtmlHelp.WriteLine();
   streamHtmlHelp.WriteLine("[OPTIONS]");
   streamHtmlHelp.WriteLine("Title="+title );
   streamHtmlHelp.WriteLine("Compatibility=1.1 or later");
   streamHtmlHelp.WriteLine("Compiled file=" + GetCompiledHtmlFilename());  //chm文件名
   streamHtmlHelp.WriteLine("Contents file=" + GetContentsHtmlFilename());  //hhc文件名
   streamHtmlHelp.WriteLine("Default topic=" + _defaultTopic);  //默认页
   streamHtmlHelp.WriteLine("Display compile progress=No"); //是否显示编译过程
   streamHtmlHelp.WriteLine("Language=0x804 中文(中国)");  //chm文件语言

   streamHtmlHelp.WriteLine();
   streamHtmlHelp.WriteLine("[INFOTYPES]");

   streamHtmlHelp.Close();
  }