I want to check if a file exists on server's disk and I am using following code
Check your source code, you use File.Existe method to determine whether the specified file exists. You source code appears to look ok, and you also can get the error information from a txt file. That proves your source code did work. I'm not sure what your
question is exactly, please check the both references below:
sparrow37
Member
302 Points
638 Posts
file exist on sever
May 03, 2012 08:14 AM|LINK
I want to check if a file exists on server's disk and I am using following 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!");
but I am getting this error:
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!
my log function likes this
c# asp.net
ziaulrahman
Member
483 Points
179 Posts
Re: file exist on sever
May 03, 2012 08:23 AM|LINK
Mark answer if it helps.
Mamba Dai - ...
All-Star
23531 Points
2683 Posts
Microsoft
Re: file exist on sever
May 10, 2012 07:24 AM|LINK
Hi,
Check your source code, you use File.Existe method to determine whether the specified file exists. You source code appears to look ok, and you also can get the error information from a txt file. That proves your source code did work. I'm not sure what your question is exactly, please check the both references below:
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
http://msdn.microsoft.com/en-us/library/system.io.fileinfo.exists.aspx
And I suggest you to debug your soucec code step by step to determine what happends and how your source code executes.
Feedback to us
Develop and promote your apps in Windows Store