Solved

Export to excel from Console app

Posted on 2013-06-04
2
1,092 Views
Last Modified: 2013-06-05
Hello Experts,
I need to export string data to excel using console app (C#) without using any third party libraries...

i am getting object reference error...HttpContext.Current.Response.ClearContent();


here is my code so far...( i have it on class library project)

using System.Web;

 private void ExportToExcel(string strData)
        {
            try
            {
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=BatchResponse.xls");
            HttpContext.Current.Response.ContentType = "application/excel";
            HttpContext.Current.Response.Write(strData);
            HttpContext.Current.Response.End();
            }
            catch (Exception ex)
            {
                log.LogExceptionError("Batch Settlement Process - ExportToExcel", ex);
            }
            finally
            {
                log = null;
            }
        }
           

Any help?

Thanks
0
Comment
Question by:mani_sai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39221291
Where is  HttpContext defined ?

As a matter of interest, if this is a console app why are you using Http to export to Excel ?
0
 
LVL 8

Author Closing Comment

by:mani_sai
ID: 39224395
Thanks. figured out the solution using StreamWriter.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question