title: How to download excel file to a specific folder in asp.net
body: <p>I need to download the excel to the specific folder </p>
  
  <p>Example : D:\email</p>
  
  <p>Now i was able to download the excel file in downloads ....but i need to download in D:\email</p>
  
  <p>this is my code to create excel file :</p>
  
  <pre><code>             protected void UploadDataTableToExcel(DataTable dtRecords)
         {
          string XlsPath = Server.MapPath(@"~/Add_data/test.xls");
          string attachment = string.Empty;
          if (XlsPath.IndexOf("\\") != -1)
          {
              string[] strFileName = XlsPath.Split(new char[] { '\\' });
              attachment = "attachment; filename=" + strFileName[strFileName.Length - 1];
          }
          else
              attachment = "attachment; filename=" + XlsPath;
          try
          {
              Response.ClearContent();
              Response.AddHeader("content-disposition", attachment);
              Response.ContentType = "application/vnd.ms-excel";
              string tab = string.Empty;
  
              foreach (DataColumn datacol in dtRecords.Columns)
              {
                  Response.Write(tab + datacol.ColumnName);
                  tab = "\t";
              }
              Response.Write("\n");
  
              foreach (DataRow dr in dtRecords.Rows)
              {
                  tab = "";
                  for (int j = 0; j &lt; dtRecords.Columns.Count; j++)
                  {
                      Response.Write(tab + Convert.ToString(dr[j]));
                      tab = "\t";
                  }
  
                  Response.Write("\n");
              }
              Response.End();
          }
          catch (Exception ex)
          {
              //Response.Write(ex.Message);
          }
              }
  </code></pre>