Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5962999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:11:06+00:00 2026-05-22T19:11:06+00:00

I m having function which export data of dataset to an excel sheet. it

  • 0

I m having function which export data of dataset to an excel sheet.
it is working fine on local machine
but whn i upload ths code to server it not work ….

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"/>

edited :

                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 xml 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:11:07+00:00Added an answer on May 22, 2026 at 7:11 pm

    Automating Word or Excel on services is strongly discouraged, but you can read some considerations about it here. First of all you could try setting your service to run as Local System. Other thing to play with is to find the Excel in the:

    Control Panel – Administrative Tools – Component services – Component services – My computer – DCOM Config

    There you can set the priviledges under which the Excel can run, etc…

    But, I have to say, even with everything setup properly it can still turn out not working. We had intense difficulties with this, with some server working, and the exact same configuration not working on some other server…

    So, what I would suggest (since your need doesn’t really require automation) is to create Excel files yourself using XSLT to create SpreadSheetML – it’s actually more easy than you’ll think at first, but it’s really a goood way to go. Try saving your XLS file in an Office XML 2003 format, and see the structure of the XML – if you look at the body it’s really not that complicated. When you create these XML’s the Excel can open it just like any other file.

    Another way (if you don’t like using XSL Transformations) is to use Open XML Format SDK – we found that one to be a bit tedious to implement for Word (we needed some nuances) so we still prefer the XSLT’s, but for Excel it could prove to be quite easy. With this SDK you can even save as XSLX/DOCX formats (which is actually very similar to ProcessingML, but packed into a zip)

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having Plugin A which extends the 'Export Wizard' via the org.eclipse.ui.exportWizard ExtensionPoint. Plugin
i have been working on a small demo and i wrote a function which
I would like to write an OCaml module having a compile function which will
Having a problem trying to create a function, as part of a BizTalk helper
Having a vector containing pointers to objects then using the clear function doesn't call
I am having some difficulty writing a function that will search through a directory
I'm having trouble creating a mouseover function with an NSTableView. The idea is that
I understand passing in a function to another function as a callback and having
I'm creating my own dictionary and I am having trouble implementing the TryGetValue function.
I'm having real difficulty with this but I'm no javascript expert. All I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.