Hi Team,
with the reference of
i have integrated code in my application.
But when i execute that code, after Document.Close(); debugger is disconnecting, nothing happens next.
Can you please help to solve this issue?
Note: document is getting saved as per code in directory:
'Save the word document as HTML file.
document.SaveAs(htmlFilePath, documentFormat)
I followed steps and code provided in below link.
Display Word document on web page in ASP.Net
Here is the code:
[HttpPost]
public string OpenDoc()
{
string ohtml = string.Empty;
System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
string savePath = ConfigurationManager.AppSettings.Get("UploadDocumentPath");
string sPath = HostingEnvironment.MapPath(savePath) + "\\";
/* Save image */
string docTitle= DateTime.Now.Ticks.ToString();
DocMediaListModel objDocMediaListModel = oDocMediaController.AddDocMedia(docTitle);
//
if (objDocMediaListModel.ListDocMediaModel[0].DocMediaId == objDocMediaListModel.UpdatedRow)
{
object documentFormat = 8;
string randomName = DateTime.Now.Ticks.ToString();
string[] strSplit = objDocMediaListModel.ListDocMediaModel[0].FileNameId.Split('.');
object htmlFilePath = sPath + randomName + ".htm";
//Open the word document in background.Add Interop namespacefor this
_Application applicationclass = new Application();
object docPath = sPath + objDocMediaListModel.ListDocMediaModel[0].FileNameId;
applicationclass.Documents.Open(ref docPath);
applicationclass.Visible = false;
Document document = applicationclass.ActiveDocument;
document.Activate();
//Save the word document as HTML file.
document.SaveAs(ref htmlFilePath, ref documentFormat);
log.Info("Test", "Before Doc close MaintainMenu", "OpenDoc", LoggedUserName);
//Close the word document.
document.Close();
log.Info("Test2", "After Dcc close MaintainMenu", "OpenDoc", LoggedUserName);
//Read the saved Html File.
string wordHTML = System.IO.File.ReadAllText(htmlFilePath.ToString());
log.Info(wordHTML, "MaintainMenu", "OpenDoc", LoggedUserName);
//Loop and replace the Image Path.
foreach (Match match in Regex.Matches(wordHTML, "<v:imagedata.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase))
{
wordHTML = Regex.Replace(wordHTML, match.Groups[1].Value, "Uploads/" + match.Groups[1].Value);
}
return wordHTML;
}
else
return ohtml;
// return ohtml;
}
Everything works fine, except document.Close();
After document.close(); debugger does not respond.
I could see new word doc instance created in Task manager.