I m having function which export data of datatable to an excel sheet.
it is working fine on local machine, or any other local machine,
but whn i upload ths code to server it not work ....
Plz help!!!!!!!!
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 12, 2010, 1:48 AM EDT
or can you paste the code which will save the excel file.
navin thangaraj35 reputationPosted May 26, 2011, 1:59 AM EDT
Posted May 26, 2011, 2:07 AM EDT
Can you please post the complete error message details?
navin thangaraj35 reputationPosted May 26, 2011, 2:11 AM EDT
code behind file:
using Excel = Microsoft.Office.Interop.Excel; using System.Reflection; using System.Drawing; using System.ComponentModel; using System.Windows.Forms; string FilePath = ConfigurationManager.AppSettings["dataqueryfile"] + "dataquery_" + DateTime.Now.ToString("yyyyMMddhhmm") ; Excel.Application oXL; Excel.Workbook oWB; Excel.Worksheet oSheet; Excel.Range oRange; // Start Excel and get Application object. oXL = new Excel.Application(); // Set some properties oXL.Visible = true; oXL.DisplayAlerts = false; // Get a new workbook. oWB = oXL.Workbooks.Add(Missing.Value); // Get the active sheet oSheet = (Excel.Worksheet)oWB.ActiveSheet; oSheet.Name = "DataQuery"; // Process the DataTable DataTable dt = ds.Tables[0]; int rowCount = 1; foreach (DataRow dr in dt.Rows) { rowCount += 1; for (int i = 1; i dt.Columns.Count + 1; i++) { // Add the header the first time through if (rowCount == 2) { oSheet.Cells[1, i] = dt.Columns[i - 1].ColumnName; } oSheet.Cells[rowCount, i] = dr[i - 1].ToString(); } } // Resize the columns oRange = oSheet.get_Range(oSheet.Cells[1, 1], oSheet.Cells[rowCount, dt.Columns.Count]); oRange.EntireColumn.AutoFit(); // Save the sheet and close oSheet = null; oRange = null; oWB.SaveAs(FilePath + ".xls", Excel.XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); oWB.Close(Missing.Value, Missing.Value, Missing.Value); oWB = null; oXL.Quit(); // Clean up // NOTE: When in release mode, this does the trick GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect();web config file :
add key="dataqueryfile" value="C:\navin\"/> add assembly="Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/> add assembly="office, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/> add assembly="Microsoft.Vbe.Interop, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/> add assembly="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>plz help me out..
thanx n regards
T.Navin
Posted May 26, 2011, 2:18 AM EDT
navin thangaraj35 reputationPosted May 26, 2011, 2:18 AM EDT
navin thangaraj35 reputationPosted May 26, 2011, 2:20 AM EDT
Posted May 26, 2011, 2:23 AM EDT
navin thangaraj35 reputationPosted May 26, 2011, 2:30 AM EDT
my local and server are the same machine...and i run the code from the local its working fine..and then i moved the aspx page to the virtual directory (inside inetpub ) and then i have try to access the same page through url the file is not getting downloaded..
how to check the read /write access to the download folder
Posted May 26, 2011, 2:36 AM EDT
the download folder is "c:\Navin\" folder as you mentioned in the config file.
navin thangaraj35 reputationPosted May 26, 2011, 2:44 AM EDT
its web application..
by mistake i have included it ... now i have removed it ...thnx
aftr removing , i have restarted the server , still the same issue is there...
i went to inetmgr, and then i , browse the virtual directory its working fine..
but when i access the same page through URL it's not working
navin thangaraj35 reputationPosted May 26, 2011, 7:30 PM EDT
i have modified my code to xml format.. da = new SqlDataAdapter(); conn.Open(); da.SelectCommand = command; da.Fill(ds); ds.WriteXml("c:\\Customers.xml");when i execute solution from the local system the data set values are copied to the xml file along with column header..then i moved the files to virtual directory under inetpub folder. through iis manager i browsed the virtual directory and run the same page , the file is getting saved in the same path but without the column header :(.. then i opened the same page from other machine through URL (thru inetrnal ip address) but the xml file is not saving to the machine.. plz help me out..
thanx n regards
T.Navin