Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Xml;
- using System.Xml.Xsl;
- using System.Windows.Forms;
- using Ionic.Zip;
- namespace DWConverter
- {
- public partial class Form1 : Form
- {
- String saveDir = "";
- String openDir = "";
- public Form1()
- {
- InitializeComponent();
- }
- private void btnOpen_Click(object sender, EventArgs e)
- {
- openFileDialog1.ShowDialog();
- }
- private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
- {
- openDir = openFileDialog1.FileName;
- txtBoxOpen.Text = openDir;
- saveDir = openDir.Replace(openFileDialog1.SafeFileName, "");
- txtBoxSave.Text = saveDir;
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- saveFileDialog1.ShowDialog();
- }
- private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
- {
- saveDir = saveFileDialog1.FileName;
- txtBoxSave.Text = saveDir;
- }
- private void btnConvert_Click(object sender, EventArgs e)
- {
- String workingDir = Directory.GetCurrentDirectory() + @"\working\";
- using (ZipFile zip = ZipFile.Read(openDir))
- {
- zip.ExtractAll(workingDir);
- }
- try
- {
- // strXMLFilePath holds the absolute path of the extracted //“Document.xml” file from the word document(*.docx)
- string strXMLFilePath = workingDir + @"\word\document.xml";
- // Lets save the XSLT (shown in the article) to a file called //“OpenXml_XSLT.xsl”
- // strXSLFilePath holds the absolute path of the “OpenXml_XSLT.xsl”
- //string strXSLFilePath = Directory.GetCurrentDirectory() + @"\DocX2Html.xsl";
- // strHtmlFilePath holds the file name & path of the HTML file to be
- // generated.In this case we save it inside the folder that holds
- // the Document.xml
- if(File.Exists(saveDir)){
- saveDir += 1;
- }
- string strHtmlFilePath = saveDir;
- //Load the Document.xml file into XmlDocument object
- XmlDocument objXmlDom = new XmlDocument();
- objXmlDom.Load(strXMLFilePath);
- //Load the XSL file(OpenXml_XSLT.xsl) into the XslCompiledTransform object
- XslCompiledTransform objXSLT = new XslCompiledTransform();
- objXSLT.Load(System.Reflection.Assembly.Load("DocX2Html").GetType("DocX2Html"));
- // The Transform method converts the XML to HTML and stores the HTML file
- // in the path specified in the variable strHtmlFilePath
- objXSLT.Transform(strXMLFilePath, strHtmlFilePath);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- Directory.Delete(workingDir, true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement