iam use this code for wire from asp.net in word but run from iis locallhost Observation this error
Object reference not set to an instance of an object.
Line 114:
Line 115: //System.Reflection.Missing.Value is used here for telling that method to use default parameter values when method execution
Line 116: oDoc = oWordApplication.Documents.Open(fileName, newTemplate, docType, isVisible, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
Line 117: ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
when run or excute from vs2012 dont error and right was set-up code with out error
.
im dont whats problem.
var realpath="~/template";
var filePath = Path.Combine(HttpContext.Current.Server.MapPath("~/template"), Lcourseid.Text + ".doc");
var oWordApplication = new Application();
DirectoryInfo dir = new DirectoryInfo(Server.MapPath(realpath));
foreach (FileInfo files in dir.GetFiles())
{
files.Delete();
}
object missing = System.Reflection.Missing.Value;
string fileName = @"D:\template1.dot";
object newTemplate = false;
object docType = 0;
object isVisible = true;
oDoc = oWordApplication.Documents.Open(fileName, newTemplate, docType, isVisible, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
if(Convert.ToInt16(oWordApplication.Version) >=11)
{
oDoc.ActiveWindow.View.ReadingLayout = false;
}
oDoc.Activate();
if (oDoc.Bookmarks.Exists("Title"))
{
oDoc.Bookmarks["Title"].Range.Text = "Test Field Entry from webform";
oDoc.Bookmarks["Address"].Range.Text = "Address Field Entry from webform";
}
oDoc.SaveAs(filePath, ref missing);
oWordApplication.Documents.Close(ref missing, ref missing, ref missing);
ProcessRequest(filePath, Lcourseid.Text);