I Publish(Deployed) My website on IIS
Everything is working Fine
But i am generating Word using Find And Replace (Mail Merge) Method,
From Visual Studio its Working
But When i open project from another computer using http://192.168.0.101/Electro/SalesInvoice.aspx
it's Not Generating Word Document
and if we check path its showing path like this ==>
D:ExportToWordExportInvoiceExportSalesInvoiceTamplate.docx
What I have tried:
protected void tpbtnExportWord_Click(object sender, EventArgs e)
{
Control FooterTemplate = Tprptr.Controls[Tprptr.Controls.Count - 1].Controls[0];
Label lblTotalAfterTax = FooterTemplate.FindControl("tplblTotalAfterTax") as Label;
Label TplblTaxableValue = FooterTemplate.FindControl("tplblTaxableValue") as Label;
Label TPlblsgst = FooterTemplate.FindControl("tplblsgst") as Label;
Label Tplblcgst = FooterTemplate.FindControl("tplblcgst") as Label;
Label TPlbligst = FooterTemplate.FindControl("tplbligst") as Label;
Label TplblTotalValue = FooterTemplate.FindControl("tplblTotalValue") as Label;
Label TPlblTotalBeforeTaxValue = FooterTemplate.FindControl("tplblTotalBeforeTaxValue") as Label;
Label TPlblTotalinWordValule = FooterTemplate.FindControl("tplblTotalinWordValule") as Label;
Label TPtotalTaxValue = FooterTemplate.FindControl("totalTaxValue") as Label;
Label TPGstOnReverceChargeValue = FooterTemplate.FindControl("tplblGstOnReverceChargeValue") as Label;
objSalesInvoiceBO.TpTotalBeforeTax = Convert.ToDecimal(TplblTaxableValue.Text.ToString());
objSalesInvoiceBO.TpTotalBeforeTax = Convert.ToDecimal(TPlblTotalBeforeTaxValue.Text.ToString());
objSalesInvoiceBO.TpTotalAfterTax = Convert.ToDecimal(lblTotalAfterTax.Text.ToString());
objSalesInvoiceBO.TpGstOnReverceCharge = TPGstOnReverceChargeValue.Text.ToString();
objSalesInvoiceBO.TpSgsttotal = Convert.ToDecimal(TPlblsgst.Text.ToString());
objSalesInvoiceBO.TpCgsttotal = Convert.ToDecimal(Tplblcgst.Text.ToString());
objSalesInvoiceBO.TpIgsttotal = Convert.ToDecimal(TPlbligst.Text.ToString());
objSalesInvoiceBO.TpTotalInWord = TPlblTotalinWordValule.Text.ToString();
objSalesInvoiceBO.TpTotalAfterTax = Convert.ToDecimal(TplblTotalValue.Text.ToString());
#region
if (expddlInvoiceTypeCategory.SelectedValue == "1")
{
object strTemplate = "D:\\ExportToWord\\TAXInvoice\\TaxInvoiceBlank.docx";
strReportPath = "D:\\ExportToWord\\TAXInvoice\\resultt.docx";
try
{
object missing = System.Reflection.Missing.Value;
object outputFileName = strReportPath;
object fileFormat;
if (File.Exists((string)strTemplate))
{
DateTime today = DateTime.Now;
object readOnly = false;
object isVisible = false;
wordApp = new Word.Application();
aDoc = null;
wordApp.Visible = false;
aDoc = wordApp.Documents.Open(ref strTemplate, 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);
aDoc.Activate();
IList<int> lstTableCounts = new List<int>();
for (int i = 1; i <= aDoc.Tables.Count; i++)
{
Word.Cell cell = aDoc.Tables[i].Cell(1, 1);
if (cell.Range.Text.Contains("<lblMultiResults>"))
{
lstTableCounts.Add(i);
}
}
int[] inttablecounts = lstTableCounts.ToArray();
if (TPInvoiceId == 0)
{
DataTable dt = new DataTable();
dt = objSalesInvoiceBL.GetTpSalesInvoiceMaxId();
string Maxid = dt.Rows[0][0].ToString();
if (dt.Rows.Count > 0)
{
objSalesInvoiceBO.TPInvoiceId = Convert.ToInt32(Maxid);
}
}
else
{
objSalesInvoiceBO.TPInvoiceId = Convert.ToInt32(TPInvoiceId);
}
DataTable dt2 = new DataTable();
DataTable dt4 = new DataTable();
dt2 = objSalesInvoiceBL.Select_TpSalesInvoiceMaterialdetailForPDF(objSalesInvoiceBO);
dt4 = objSalesInvoiceBL.Select_TpSalesInvoiceMaterialdetailForSupplierPoNo(objSalesInvoiceBO);
if (dt2 != null)
{
if (dt2.Rows.Count > 0)
{
#region Code for Multiple Results table
foreach (var d in inttablecounts)
{
string[] strcol;
strcol = new string[aDoc.Tables[d].Columns.Count];
for (int i = 1; i <= aDoc.Tables[d].Columns.Count; i++)
{
Word.Cell cell = aDoc.Tables[d].Cell(3, i);
strcol[i - 1] = cell.Range.Text.Replace("\r", "").Replace("\a", "");
}
for (int i = 1; i < dt2.Rows.Count; i++)
{
aDoc.Tables[1].Rows.Add(aDoc.Tables[d].Rows[i + 2]);
for (int j = 1; j <= aDoc.Tables[d].Columns.Count; j++)
{
Word.Cell cell = aDoc.Tables[d].Cell(i + 2, j);
cell.Range.Text = strcol[j - 1].Substring(0, strcol[j - 1].Length - 1) + " " + i + ">";
}
}
for (int i = 1; i <= aDoc.Tables[d].Columns.Count; i++)
{
Word.Cell cell = aDoc.Tables[d].Cell(dt2.Rows.Count + 2, i);
cell.Range.Text = strcol[i - 1].Substring(0, strcol[i - 1].Length - 1) + " " + dt2.Rows.Count + ">";
}
try
{
for (int j = 1; j <= aDoc.Tables[d].Columns.Count; j++)
{
Word.Cell cell = aDoc.Tables[d].Cell(1, j);
cell.Range.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;
cell.Range.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;
cell.Range.Borders[Word.WdBorderType.wdBorderTop].LineStyle = Word.WdLineStyle.wdLineStyleNone;
}
}
catch (Exception ex)
{
}
}
FindAndReplace(wordApp, "<tinvoiceno>",
dt4.Rows[0]["TpAutoNumber"].ToString());
FindAndReplace(wordApp, "<tinvoicedate>",
dt4.Rows[0]["TpInvoiceDate"].ToString());
FindAndReplace(wordApp, "<lblMultiResults>", "");
for (int i = 1; i <= dt2.Rows.Count; i++)
{
FindAndReplace(wordApp, "<mulSrNo " + i + ">", i.ToString());
FindAndReplace(wordApp, "<mulpdescription " + i + ">",
dt2.Rows[i - 1]["Product Description HSN/HAC Code"].ToString());
FindAndReplace(wordApp, "<mulpqty " + i + ">",
dt2.Rows[i - 1]["Qty(Unit)"].ToString());
}
}
}
if (dt2.Rows[0][0].ToString() == "No")
{
outputFileName = strTemplate.ToString().Replace(".docx", ".pdf");
fileFormat = Word.WdSaveFormat.wdFormatPDF;
}
else
{
fileFormat = Word.WdSaveFormat.wdFormatDocumentDefault;
}
}
else
{
System.Windows.Forms.MessageBox.Show("File dose not exist.");
return;
}
aDoc.SaveAs(ref outputFileName, ref fileFormat, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
aDoc.Close(ref saveChanges, ref missing, ref missing);
wordApp.Quit();
System.Diagnostics.Process.Start(@outputFileName.ToString());
}
catch (Exception ex)
{
}
}
}