Added button to convert MSWord sections to DocX

This commit is contained in:
Rich
2016-09-13 21:11:28 +00:00
parent f989e52a13
commit 54334cc233
2 changed files with 56 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;
using Volian.Controls.Library;
using DescriptiveEnum;
using System.IO;
namespace VEPROMS
{
@@ -206,7 +207,7 @@ namespace VEPROMS
using (Content cont = Content.Get(sectinfo.MyContent.ContentID))
{
Byte[] tstbyte = System.Text.Encoding.Default.GetBytes("");
Document doc = Document.MakeDocument(null, tstbyte, null, null,".RTF"); // tstbyte, null, null, null);
Document doc = Document.MakeDocument(null, tstbyte, null, null,".DOCX"); // RTF Caused B2016-196 Changed to DOCX for default
Entry entry = cont.MyEntry;
entry.MyDocument = Document.Get(doc.DocID);
cont.Save();
@@ -490,6 +491,7 @@ namespace VEPROMS
if (_SectionConfig.MySection.MyContent.MyEntry!=null && _SectionConfig.MySection.MyContent.MyEntry.MyDocument!=null && (_SectionConfig.MySection.MyContent.MyEntry.MyDocument.LibTitle != null) && (_SectionConfig.MySection.MyContent.MyEntry.MyDocument.LibTitle != "")) isLib = true;
if (isLib)
{
ppBtnConvertToDocX.Visible = false; // Don't allow save as DOCX for libraries documents
ppBtnCvrtToLibDoc.Text = "Convert this Section To A Non-Library Document";
lblLibraryDocument.Text = "Library Document";
superTooltip1.SetSuperTooltip(this.ppBtnCvrtToLibDoc, new DevComponents.DotNetBar.SuperTooltipInfo("Convert To Non-Library Document", "", "This button will convert the current section from a library document to a non-library document",
@@ -497,6 +499,10 @@ namespace VEPROMS
}
else
{
if (_SectionConfig.MySection.MyContent.MyEntry.MyDocument != null && _SectionConfig.MySection.MyContent.MyEntry.MyDocument.FileExtension == ".RTF")
this.ppBtnConvertToDocX.Visible = true; // Only allow save as DocX for normal word sections when the exissting text is RTF.
else
this.ppBtnConvertToDocX.Visible = false;
if (_SectionConfig.MySection.MyContent.MyEntry.MyDocument == null)
ppBtnCvrtToLibDoc.Visible = false;
else
@@ -1167,7 +1173,39 @@ namespace VEPROMS
}
}
}
private void ppBtnConvertToDocX_Click(object sender, EventArgs e)
{
// Get Document as file
ItemInfo ii = ItemInfo.Get(_SectionConfig.MySection.ItemID);
DocumentInfo doclibinfo = ii.MyContent.MyEntry.MyDocument;
DSOFile myfile = new DSOFile(doclibinfo);
// When trying to fix this , the update of the document waas causing a CSLA crash so I switched
// to make document
//using (Document myDoc = doclibinfo.Get())
//{
// Open MSWord App
LBWordLibrary.LBApplicationClass ap = new LBWordLibrary.LBApplicationClass();
LBWordLibrary.LBDocumentClass doc = ap.Documents.Open(myfile.FullName);
string filename = myfile.FullName.ToUpper().Replace(".RTF", ".DOCX");
doc.SaveAs(filename, LBWordLibrary.LBWdSaveFormat.wdFormatXMLDocument); // Convert to DocX
doc.Close();
ap.Quit();
FileInfo fi = new FileInfo(filename);
FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);// B2016-053
long len = fs.Length;
byte[] ByteArray = new byte[len];
int nBytesRead = fs.Read(ByteArray, 0, (int)len);
fs.Close();
Document myDoc = Document.MakeDocument(null, ByteArray, doclibinfo.DocAscii, doclibinfo.Config, ".DOCX");
_SectionConfig.MySection.MyContent.MyEntry.MyDocument = myDoc;
_SectionConfig.MySection.MyContent.MyEntry.Save();
//myDoc.DocContent = ByteArray;
//myDoc.FileExtension = ".DOCX";
//myDoc.Save();
fi.Delete();// Cleanup afterwards
ppBtnConvertToDocX.Visible = false; // Hide the button after the execution is complete.
//}
}
//private void ppBtnDefaultPrintSize_Click(object sender, EventArgs e)
//{
// // Get the parent setting