lagyossarian
New member
- Joined
- Apr 7, 2006
- Messages
- 2
- Programming Experience
- 5-10
I have an ASP.NET 2.0 web application. This application has a command button that triggers some code to happen. It works on my development box; but, when I deploy to my test server, it does not appear to execute. The page appears to just repost. I included some Response.Write statements to use for debugging and none of them are displaying on the reposted page. The code is posted below:
protected void btnExecute_Click(object sender, EventArgs e)
{
String strPath;
Microsoft.Office.Interop.Excel.Application objExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook objWorkbook = null;
Object missing = Type.Missing;
if (Page.IsPostBack)
{
Response.Write("Button clicked");
try
{
connProviders.ConnectionString = SqlDataSource1.ConnectionString;
SqlCommand cmdReports = new SqlCommand();
cmdReports.Connection = connProviders;
cmdReports.CommandType = CommandType.StoredProcedure;
cmdReports.CommandText = "GetReports";
SqlDataAdapter daReports = new SqlDataAdapter(cmdReports);
DataSet dsReports = new DataSet("Reports");
Response.Write("Fill dsReports");
daReports.Fill(dsReports);
Response.Write("dsReports filled");
foreach (ListItem l in lstProviders.Items)
{
if (l.Selected == true)
{
foreach (TreeNode pn in trvReports.Nodes)
{
foreach (TreeNode cn in pn.ChildNodes)
{
if (cn.Checked == true)
{
foreach (DataRow d in dsReports.Tables[0].Rows)
{
if (cn.Text == d["NodeName"].ToString())
{
strPath = d["FileLocation"].ToString() + l.Text + @"\" + d["NodeName"].ToString() + @"\" + l.Text + " - " + d["ReportName"].ToString() + "." + d["ReportType"].ToString();
if (File.Exists(strPath))
{
try
{
switch (d["ReportType"].ToString())
{
case "xls":
Response.Write("Made it to Excel Activation");
objWorkbook = objExcel.Workbooks.Open(strPath, 1, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Response.Write("Opened Excel object");
objWorkbook.PrintOut(missing, missing, missing, missing, missing, missing, missing, missing);
Response.Write("Printed Excel object");
break;
}
}
catch (Exception DocEx)
{
MessageBox.Show("Problem with file " + strPath);
}
finally
{
if (objWorkbook != null)
{
objWorkbook.Close(0, missing, missing);
}
}
}
}
}
}
}
}
}
}
objExcel.Quit();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
I'm fairly new to ASP.NET and am stuck. Any help/guidance is much appreciated. Thanks in advance.
protected void btnExecute_Click(object sender, EventArgs e)
{
String strPath;
Microsoft.Office.Interop.Excel.Application objExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook objWorkbook = null;
Object missing = Type.Missing;
if (Page.IsPostBack)
{
Response.Write("Button clicked");
try
{
connProviders.ConnectionString = SqlDataSource1.ConnectionString;
SqlCommand cmdReports = new SqlCommand();
cmdReports.Connection = connProviders;
cmdReports.CommandType = CommandType.StoredProcedure;
cmdReports.CommandText = "GetReports";
SqlDataAdapter daReports = new SqlDataAdapter(cmdReports);
DataSet dsReports = new DataSet("Reports");
Response.Write("Fill dsReports");
daReports.Fill(dsReports);
Response.Write("dsReports filled");
foreach (ListItem l in lstProviders.Items)
{
if (l.Selected == true)
{
foreach (TreeNode pn in trvReports.Nodes)
{
foreach (TreeNode cn in pn.ChildNodes)
{
if (cn.Checked == true)
{
foreach (DataRow d in dsReports.Tables[0].Rows)
{
if (cn.Text == d["NodeName"].ToString())
{
strPath = d["FileLocation"].ToString() + l.Text + @"\" + d["NodeName"].ToString() + @"\" + l.Text + " - " + d["ReportName"].ToString() + "." + d["ReportType"].ToString();
if (File.Exists(strPath))
{
try
{
switch (d["ReportType"].ToString())
{
case "xls":
Response.Write("Made it to Excel Activation");
objWorkbook = objExcel.Workbooks.Open(strPath, 1, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Response.Write("Opened Excel object");
objWorkbook.PrintOut(missing, missing, missing, missing, missing, missing, missing, missing);
Response.Write("Printed Excel object");
break;
}
}
catch (Exception DocEx)
{
MessageBox.Show("Problem with file " + strPath);
}
finally
{
if (objWorkbook != null)
{
objWorkbook.Close(0, missing, missing);
}
}
}
}
}
}
}
}
}
}
objExcel.Quit();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
I'm fairly new to ASP.NET and am stuck. Any help/guidance is much appreciated. Thanks in advance.