C# version of turning a website into a chm file. Requires that html workshop (http://msdn.microsoft.com/library/en-us/htmlhelp/html/vsconhh1start.asp) is installed. If anyone knows of a working open source chm compiler let me know.
Can be used like:
html2chm.Html2chm action = new html2chm.Html2chm();
This will run and prompt you for which website directory and which file in the directory to convert to a chm file.
Or it can be used like this:
bool eachFileAsTopic = true;
html2chm.Html2chm action = new html2chm.Html2chm(@"\\Path\to\directory\to\convert", @"mainTopic.html", eachFileAsTopic);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
namespace html2chm
{
public class Html2chm
{
//http://www.majorsilence.com/csharp_html2chm
//The generated CHM file is named YourCHMFile.chm on your desktop.
string HHC;
// Path to hhc.exe
// Directory path where HHP file is stored
// and base directory of the html files to be converted
string RepBase;
string FicHHP;
// Path to HHP file
string fileListString;
public Html2chm() : this("", "", false)
{
}
public Html2chm(string convertDirectory, string mainTopic, bool filesAsTopics)
{
List fileList = new List();
HHC = System.IO.Path.Combine("C:\\Program Files\\HTML Help Workshop", "hhc.exe");
if (System.IO.File.Exists(HHC) == false)
{
HHC = System.IO.Path.Combine("C:\\Program Files (x86)\\HTML Help Workshop", "hhc.exe");
if (System.IO.File.Exists(HHC) == false)
{
MessageBox.Show("In order to use this script, you need HTML Help Workshop" + System.Environment.NewLine + "http://msdn.microsoft.com/library/en-us/htmlhelp/html/vsconhh1start.asp");
return;
}
}
if (convertDirectory == string.Empty)
{
System.Windows.Forms.FolderBrowserDialog DirectoryBrowser = default(System.Windows.Forms.FolderBrowserDialog);
DirectoryBrowser = new System.Windows.Forms.FolderBrowserDialog();
DirectoryBrowser.Description = "Which directory do you want to use?";
if ((DirectoryBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK))
{
RepBase = DirectoryBrowser.SelectedPath;
}
}
else
{
RepBase = convertDirectory;
}
if (RepBase == null)
{
MessageBox.Show("Please choose a Folder");
}
else
{
fileList.AddRange(RecursiveFileList(new DirectoryInfo(RepBase), new DirectoryInfo(RepBase)));
string fileHHC="";
string FicHHC = System.IO.Path.Combine(RepBase, "chm-editor-Temp-HHC.hhc");
foreach (string s in fileList)
{
this.fileListString += s + System.Environment.NewLine;
if (filesAsTopics)
{
string value = s.Replace(RepBase, "");
string textValue = "";
if (value.StartsWith("\\"))
{
value = value.Remove(0, 1);
}
textValue = System.IO.Path.GetFileName(value);
textValue = textValue.Replace(System.IO.Path.GetExtension(textValue), "");
fileHHC += "
Recent comments
1 week 4 days ago
1 week 5 days ago
1 week 6 days ago
1 week 6 days ago
1 week 6 days ago
2 weeks 5 days ago
2 weeks 6 days ago
2 weeks 6 days ago
3 weeks 3 days ago
3 weeks 4 days ago