[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

Gridview image in Excel file

Dear Friends,

the gridview contain the image, i want to export the gridview in excel format and its working fine, the only problem is image is not visible in excel file.

i searched on the google but not found the solution.

please check the attached codes for converting gridview to excel.

please let me know the solution asap.

thanx
private void ExportGridView()
    {
        Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");

        Response.ContentType = "application/excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);

        gv.RenderControl(htw);

        Response.Write(sw.ToString());

        Response.End();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {

    }

Open in new window

0
virafh
Asked:
virafh
  • 3
  • 2
2 Solutions
 
princeatapiCommented:

Try Using This ?

       Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
        Response.Charset = String.Empty;
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter sw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.RenderControl(hw);
        Response.Write(sw.ToString());
        Response.End();
0
 
virafhAuthor Commented:
same issue, images are not showing
0
 
princeatapiCommented:
You can get the image to show if you use an absolute URL to refer to the
 image instead of a relative one.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
Kumaraswamy RCommented:
Hi

Bellow url give some information on ur Code

http://www.aspdotnetcodes.com/Export_GridView_To_Excel_With_Image.aspx
0
 
virafhAuthor Commented:
i got this link, but for that , i have change my codes a lot , please try to solve the problem with my codes, which i posted in first thread

thanx
0
 
virafhAuthor Commented:

i solved it by just setting <asp:ImageField> in gridview
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now