title: File exist on server using C#, asp.net
body: <p>I want to check if a file exists on server's disk and I am using following code</p>
  
  <pre><code>if (File.Exists(Server.MapPath("~/Jaram Images/") + Path.GetFileName(product.Pic_Url2)))
                                              {
                                                  WriteError("File  exist!");
  
                                                  //PdfProdCell = new PdfPCell(iTextSharp.text.Image.GetInstance(Server.MapPath("~/Jaram Images/") + Path.GetFileName(product.Pic_Url2)), true);
                                              }
                                              else
                                                  WriteError(Server.MapPath("~/Jaram Images/") + " File doesn't exist!");
  </code></pre>
  
  <p>but I am getting this error:</p>
  
  <pre><code>public static void WriteError(string errorMessage)
  {
      try
      {
          string path = "~/Jaram PDF/PDFS/" + DateTime.Today.ToString("dd-mm-yy") + ".txt";
          if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
          {
              File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close();
          }
          using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path)))
          {
              w.WriteLine("\r\nLog Entry : ");
              w.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
              string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
                            ". Error Message:" + errorMessage;
              w.WriteLine(err);
              w.WriteLine("__________________________");
              w.Flush();
              w.Close();
          }
      }
      catch (Exception ex)
      {
          WriteError(ex.Message);
      }
  
  }
  
  Log Entry : 
  05/03/2012 15:50:51
  Error in: http://localhost/WebStore/AdminNewAccount.aspx?role=+Administrator. Error Message:C:\inetpub\wwwroot\WebStore\Jaram Images\ File doesn't exist!
  </code></pre>
  
  <hr>
  
  <p>my log function likes this</p>