Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object oMissing = System.Reflection.Missing.Value;
DirectoryInfo dirInfo = new DirectoryInfo(@"D:\Doc");
FileInfo[] wordFiles = dirInfo.GetFiles("*.docx");
word.Visible = false;
word.ScreenUpdating = false;
foreach (FileInfo wordFile in wordFiles)
{
Object filename = (Object)wordFile.FullName;
if (wordFile.ToString() == "Offer letter.docx")
{
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Document doc = word.Documents.Open(ref filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".docx", ".pdf");
object fileFormat = WdSaveFormat.wdFormatPDF;
doc.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
}
}
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;
It is giving Error at line
"doc.Activate()".
Error Stack Trace is:
[NullReferenceException: Object reference not set to an instance of an object.]
HRM_Letters_OfferLetter.btnsave_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\02-02-2015 HRM\Web\HRM Letters\OfferLetter.aspx.cs:210
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +114
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +139
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +28
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2980
By executing this ,am getting "System.NullReferenceException: Object reference not set to an instance of an object." error in c#.net.pleae anybody help me.
In my machine am getting output, when it is in IIS getting this error.What's wrong in my coding plase any one help me.