Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

export grid view to excel encoding problem

Posted on 2011-09-18
4
Medium Priority
?
3,474 Views
Last Modified: 2012-05-12
i am exporting grid view into excel
but i am having problem in encoding
arabic characters are not displayed properly  
 
public void ExportGridViewToExcel(HttpResponse Response, GridView GridView_Excel)
    {
        string attachment = "attachment; filename=Transactions.xls";

        Response.ClearContent();

        HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
        HttpContext.Current.Response.Charset = "utf-8";

        Response.AddHeader("content-disposition", attachment);

        Response.ContentType = "application/ms-excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);

        GridView_Excel.RenderControl(htw);

        Response.Write(sw.ToString());

        Response.End();

    }

Open in new window


any help ??? !!!!!!
public void ExportGridViewToExcel(HttpResponse Response, GridView GridView_Excel)
    {
        string attachment = "attachment; filename=Transactions.xls";

        Response.ClearContent();

        HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
        HttpContext.Current.Response.Charset = "utf-8";

        Response.AddHeader("content-disposition", attachment);

        Response.ContentType = "application/ms-excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);

        GridView_Excel.RenderControl(htw);

        Response.Write(sw.ToString());

        Response.End();

    }

Open in new window

0
Comment
Question by:AhmedHindy
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 1500 total points
ID: 36559128

Add Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />") in your code.

Refer: http://forums.asp.net/t/1467766.aspx

0
 
LVL 4

Author Closing Comment

by:AhmedHindy
ID: 36954698
it worked
0
 
LVL 4

Author Comment

by:AhmedHindy
ID: 37023762
add this and it worked
:)

Response.Charset = "";
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

877 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