Solved

Export to excel from Console app

Posted on 2013-06-04
2
1,078 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 56

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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