Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2006, 01:34 PM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lagyossarian
Default Problem executing code

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems executing code Neal Access VBA 1 December 11th, 2006 04:07 AM
Problem executing code from Pro C# book leo05 General .NET 0 February 22nd, 2005 04:42 PM
Problem on executing code on server!! mkmaurya_it General .NET 0 February 11th, 2005 07:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.