I am editing a word document in the browser itself. Every time I press the save button it will generate a duplicate copy. How can I avoid this duplicate copy in asp.net?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Interop;
using Microsoft.Office;
public partial class MSWord_Display : System.Web.UI.Page
{
string strPath = @"D:\sss\Tree\Tree\Tree\sand1.doc";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ApplicationClass oWordApp = new ApplicationClass();
object fileName = strPath;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
try
{
Document oWordDoc = oWordApp.Documents.Open(
ref fileName,
ref missing, ref readOnly,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,
ref missing, ref missing, ref missing, ref missing);
oWordDoc.Activate();
txtword.Text = oWordDoc.Content.Text;
oWordDoc.Save();
oWordDoc.Close(ref missing, ref missing, ref missing);
}
catch (Exception ex)
{
divMsword.InnerHtml = "OOPs <b style='color:red;'>Error Encountered Error while Reading The document" + ex.Message + " </b>";
}
}
}
protected void save_Click(object sender, EventArgs e)
{
ApplicationClass oWordApp = new ApplicationClass();
object fileName = strPath;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
try
{
Document oWordDoc = oWordApp.Documents.Open(
ref fileName,
ref missing, ref readOnly,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,
ref missing, ref missing, ref missing, ref missing);
oWordDoc.Activate();
oWordDoc.Content.InsertAfter(txtword.Text);
oWordDoc.Save();
oWordDoc.Close(ref missing, ref missing, ref missing);
divMsword.InnerHtml = "<b>Saved Sucess Fully </b> ";
}
catch(Exception ex)
{
divMsword.InnerHtml = "OOPs while saving <b style='color:red;'>Error Encountered Error while Reading The document" + ex.Message + " while saving </b>";
}
}
}
[edit]Code block, subject moved into question body - OriginalGriff[/edit]