Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5987199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:46:49+00:00 2026-05-22T22:46:49+00:00

in my application im exporting gridview data to excel sheet now i want save

  • 0

in my application im exporting gridview data to excel sheet now i want save this sheet to a folder that i have created in my machine how can i do that

i have written code like this

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    public override void VerifyRenderingInServerForm(Control control)
    {
    }


    private void ExportToExcel(string strFileName, GridView dg)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/vnd.ms-excel";
        Response.Charset = "";
        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
        oHtmlTextWriter.WriteLine("<b><u><font size='5'><font color='blue'><center> REPORT </center></font></u></b>");
        GridView1.RenderControl(oHtmlTextWriter);
        Response.End();
    } 
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("");
        con.Open();
        int var = DropDownList1.SelectedIndex;
        switch (var)
        {

            case 0: break;
            case 1: SqlCommand cmdd = new SqlCommand("update t1 set diff1=isnull(t1.date-t2.date,0)from reporttemp t1 left join reporttemp t2 on t1.rn=t2.rn+1", con);
                SqlCommand cmdd1 = new SqlCommand("update t1 set diff2=isnull(t1.date-t2.date,0)from reportpre t1 left join reportpre t2 on t1.rn=t2.rn+1", con);
                SqlCommand cmdd2 = new SqlCommand("update t1 set diff3=isnull(t1.date-t2.date,0)from reportph t1 left join reportph t2 on t1.rn=t2.rn+1", con);
                cmdd.ExecuteNonQuery();
                cmdd1.ExecuteNonQuery();
                cmdd2.ExecuteNonQuery();
                GridView1.Visible = true;
                DataTable dt = new DataTable();
                SqlCommand cmd = new SqlCommand("select Date,Temperature from reporttemp where datepart(minute,diff1)=5", con);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                SqlCommand cmd2 = new SqlCommand("select Date,Pressure  from reportpre where datepart(minute,diff2)=5", con);
                SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
                SqlCommand cmd3 = new SqlCommand("select Date,Ph  from reportph where datepart(minute,diff3)=5", con);
                SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
                da.Fill(dt);
                da2.Fill(dt);
                da3.Fill(dt);
                GridView1.DataSource = dt;
                GridView1.DataBind();
                break;
            case 2: GridView1.Visible = true;
                SqlCommand cmd4 = new SqlCommand("update t1 set diff1=isnull(t1.date-t2.date,0)from reporttemp t1 left join reporttemp t2 on t1.rn=t2.rn+1", con);
                SqlCommand cmd1 = new SqlCommand("update t1 set diff2=isnull(t1.date-t2.date,0)from reportpre t1 left join reportpre t2 on t1.rn=t2.rn+1", con);
                SqlCommand cmd5 = new SqlCommand("update t1 set diff3=isnull(t1.date-t2.date,0)from reportph t1 left join reportph t2 on t1.rn=t2.rn+1", con);
                cmd4.ExecuteNonQuery();
                cmd1.ExecuteNonQuery();
                cmd5.ExecuteNonQuery();
                GridView1.Visible = true;
                DataTable dt1 = new DataTable();
                SqlCommand cmd6 = new SqlCommand("select Date,Temperature from reporttemp  where datepart(minute,diff1)=2 ", con);
                SqlDataAdapter daa = new SqlDataAdapter(cmd6);
                SqlCommand cmd7 = new SqlCommand("select Date,Pressure  from reportpre where datepart(minute,diff2)=2", con);
                SqlDataAdapter daa2 = new SqlDataAdapter(cmd7);
                SqlCommand cmd8 = new SqlCommand("select Date,Ph  from reportph where datepart(minute,diff3)=2", con);
                SqlDataAdapter daa3 = new SqlDataAdapter(cmd8);
                daa.Fill(dt1);
                daa2.Fill(dt1);
                daa3.Fill(dt1);
                GridView1.DataSource = dt1;
                GridView1.DataBind();
                break;
        }
    }


    protected void Button3_Click1(object sender, EventArgs e)
    {
         ExportToExcel("Report.xls", GridView1);    
    }
}

can any1 help me on this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:46:50+00:00Added an answer on May 22, 2026 at 10:46 pm

    First of all use StreamWriter to write the stream

    FileStream fileStream = new FileStream(@"Location+Filename.xls", FileMode.Create);
    

    and further if you want to save it in My Documents Folder You have to use

    Environment.SpecialFolder.MyDocuments
    

    For more Info regarding this click

    Hope will help….. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET 2.0 application under IIS that has the functionnality of exporting
We've added performance measures to our application and are exposing them using JMX. Now
I have an Internet Explorer only web application. I'm exploring what we can do
Application has an auxiliary thread. This thread is not meant to run all the
The application my team is currently developing has a DLL that is used to
I make a distributed embedded application that will make use of several micro-controllers. The
I have a project that adds elements to an AutoCad drawing. I noticed that
I'm exploring the possibility of writing an application in Erlang, but it would need
Application able to record error in OnError, but we are not able to do
Application frameworks such as DotNetNuke, Eclipse, Websphere and so forth are available today which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.