Home > Article > Web Front-end > InvokeMember opens a Word document and saves it as an Html page. How to close the Html first and then exit Word? _html/css_WEB-ITnose
public partial class CountyTown : System.Web.UI.Page
{
public string countyName = string.Empty; //Township name
public string documentFullName = string.Empty; //Full plan weigh ( Including suffix name)
public string documentName = string.Empty; //Plan name
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
//Get the file name based on the passed township name
countyName = Request["space"];
documentFullName = "Jiangtan Township's prevention of typhoons and flash floods Prevention plan.docx";
documentName = documentFullName.Substring(0,documentFullName.LastIndexOf('.'));
>
Type wordType = word.GetType();
Documents docs = word.Documents; // Open file
Type docsType = docs.GetType();
object fileName = Server.MapPath(@"~UpLoad") documentFullName;
Document doc = (Document )docsType.InvokeMember("Open",BindingFlags.InvokeMethod,null, docs,new Object[]{fileName, true, true }); // Convert format, save as
Type docType = doc .Gettype ();
Object savefilename = server.mappath (@"upload") documentname ".html"; ClientScript .RegisterClientScriptBlock(GetType(), "", "
//Save HTML (Error: Word cannot save this file because it has been opened elsewhere. )
docType.InvokeMember("SaveAs",BindingFlags.InvokeMethod, null, doc, new object[] {
saveFileName, WdSaveFormat.wdFormatHTML });
// Exit Word
wordType.InvokeMember("Quit",BindingFlags.InvokeMethod, null, word, null);
Response.Redirect("~/Upload/" documentName ".html"); 🎜>
Reply to the discussion (solution)