- PUSHD <UNC PATH> will create a temporary virtual drive and get into it
- POPD will delete the temporary drive and get you back to the path you were when you entered pushd
“No problem can be solved from the same level of consciousness that created it.” Albert Einstein (1879-1955)
Wednesday 29 November 2017
Browse UNC path using Windows CMD
Saturday 25 November 2017
Sunday 19 November 2017
Thursday 16 November 2017
Convert HTML to Docx and Pdf using Microsoft.Office.Interop.Word
// use _Application and _Document instead of var to avoid ambiguities
_Application word = new Application();
_Document document = word.Documents.Open(FileName: @"C:\index.html", ConfirmConversions: false, ReadOnly: false);
word.Visible = false;
// impersonated user must have read-write access to the following locations
var pdfOutputFile = @"C:\Temp\document.pdf";
var docOutputFile = @"C:\Temp\document.docx";
byte[] Content = null;
.
.
.
case "pdf":
document.SaveAs2(FileName: pdfOutputFile, FileFormat: WdSaveFormat.wdFormatPDF);
document.Close();
word.Quit();
Content = File.ReadAllBytes(pdfOutputFile);
break;
case "docx":
foreach (InlineShape image in document.InlineShapes)
{
// make sure images are embeded
if (image.LinkFormat != null)
{
try
{
image.LinkFormat.SavePictureWithDocument = true;
image.LinkFormat.BreakLink();
}
catch { /* do nothing */ }
}
}
document.SaveAs2(FileName: docOutputFile, FileFormat: WdSaveFormat.wdFormatDocumentDefault);
document.Close();
word.Quit();
Content = File.ReadAllBytes(docOutputFile);
break;
.
.
.
// download file as byte[]
if (Content != null)
{
Response.AddHeader("content-disposition", "attachment; filename=" + (pdfOutputFile or docOutputFile));
Response.BufferOutput = true;
Response.OutputStream.Write(Content, 0, Content.Length);
Response.End();
}
Important notes:
_Application word = new Application();
_Document document = word.Documents.Open(FileName: @"C:\index.html", ConfirmConversions: false, ReadOnly: false);
word.Visible = false;
// impersonated user must have read-write access to the following locations
var pdfOutputFile = @"C:\Temp\document.pdf";
var docOutputFile = @"C:\Temp\document.docx";
byte[] Content = null;
.
.
.
case "pdf":
document.SaveAs2(FileName: pdfOutputFile, FileFormat: WdSaveFormat.wdFormatPDF);
document.Close();
word.Quit();
Content = File.ReadAllBytes(pdfOutputFile);
break;
case "docx":
foreach (InlineShape image in document.InlineShapes)
{
// make sure images are embeded
if (image.LinkFormat != null)
{
try
{
image.LinkFormat.SavePictureWithDocument = true;
image.LinkFormat.BreakLink();
}
catch { /* do nothing */ }
}
}
document.SaveAs2(FileName: docOutputFile, FileFormat: WdSaveFormat.wdFormatDocumentDefault);
document.Close();
word.Quit();
Content = File.ReadAllBytes(docOutputFile);
break;
.
.
.
// download file as byte[]
if (Content != null)
{
Response.AddHeader("content-disposition", "attachment; filename=" + (pdfOutputFile or docOutputFile));
Response.BufferOutput = true;
Response.OutputStream.Write(Content, 0, Content.Length);
Response.End();
}
Important notes:
- In order to be able to save document, create a new "Desktop" directory inside of "C:\Windows\SysWOW64\config\systemprofile\"
- The library will not work on Server 2016 with O365 or Office 2016. On server 2016, need to use Office 2013.
Subscribe to:
Posts (Atom)
Upgrade Windows 11 Home to Windows 11 Pro
Disable internet connection (Wi-Fi, Internet, etc.) Change the product key using the following Generic product key: VK7J...
-
//convert BASE64 string to Byte{} array function base64ToArrayBuffer(base64) { var binaryString = window.atob(base64); var binar...
-
static void Main(string[] args) { // create a dummy list List<string> data = GetTheListOfData(); // split the lis...
-
Add the following method to _Host.cshtml file: <script> Blazor.defaultReconnectionHandler._reconnectCallback = function(d) { ...