Solved

export grid view to excel encoding problem

Posted on 2011-09-18
4
3,032 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 12

Expert Comment

by:jagssidurala
Comment Utility
0
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 500 total points
Comment Utility

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
Comment Utility
it worked
0
 
LVL 4

Author Comment

by:AhmedHindy
Comment Utility
add this and it worked
:)

Response.Charset = "";
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now