title: Deleting existing file to specific folder
body: <p>Good day,</p>
  
  <p>I created a simple web application that can save a .csv file to specific folder on my web application..but i there something on my code that does not save it on my specific folder.I NEED to save that .csv file to that folder.</p>
  
  <p>here is my code..</p>
  
  <pre><code>        protected void btnERSFRSWRSQuery_Click(object sender, EventArgs e)
               {
               grdQueryTotal.DataSource =   _dVizOutputBll.GetERSFRSQRSQueryResultList(_totalValueTableEntities);
              grdQueryTotal.DataBind();
  
         string fname = "ERSFRSWRSQueryTotal.csv";
  
          string fLocation = HttpContext.Current.Server.MapPath("/data/" + fname);
          StreamWriter sw = new StreamWriter(fLocation,true); //("C:\\Users\\jessr\\Desktop\\GTML\\GTML\\WebApplication1\\data\\gridview.csv");
  
  
  
          //if (File.Exists(fname))
          //{
  
          //    File.Delete(fname);
          //    sw.Close();
          //}
          //else
          //{
  
              for (int i = 0; i &lt; grdQueryTotal.Columns.Count; i++)
              {
                  sw.Write(grdQueryTotal.Columns[i].HeaderText);
                  if (i != grdQueryTotal.Columns.Count)
                  {
                      sw.Write(",");
                  }
              }
              // add new line
              sw.Write(sw.NewLine);
              // iterate through all the rows within the gridview
              foreach (GridViewRow dr in grdQueryTotal.Rows)
              {
                  // iterate through all colums of specific row
                  for (int i = 0; i &lt; grdQueryTotal.Columns.Count; i++)
                  {
                      // write particular cell to csv file
                      sw.Write(dr.Cells[i].Text);
                      if (i != grdQueryTotal.Columns.Count)
                      {
                          sw.Write(",");
                      }
                  }
                  // write new line
                  sw.Write(sw.NewLine);
              }
  
              // flush from the buffers.
              sw.Flush();
              // closes the file
              sw.Close();
          //}
      }
  }
  </code></pre>
  
  <p>but first i will check if the csv file already exist in my destination folder if that exists i will delete it, if not then i will save a new csv file</p>