save excel sheet to a particular folder that i have created in my local machine and make this excel sheet as read only 
<p>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</p>

<p>i have written code like this</p>

<pre><code>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("&lt;b&gt;&lt;u&gt;&lt;font size='5'&gt;&lt;font color='blue'&gt;&lt;center&gt; REPORT &lt;/center&gt;&lt;/font&gt;&lt;/u&gt;&lt;/b&gt;");
        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);    
    }
}
</code></pre>

<p>can any1 help me on this</p>
