Following code transfer file successfully, but does not print in lable that it has been transferred. Although other checks were shown perfectly. Is there any logical eror in it?
if (txtFile1.HasFile)
{
var folderfile1 = Server.MapPath("~/files/Operations_Support/IMSI");
string flFile1 = txtFile1.PostedFile.FileName;
string saveflFile1 = folderfile1 + "\\" + System.IO.Path.GetFileName(flFile1);
FileInfo Finfo = new FileInfo(txtFile1.PostedFile.FileName);
if (Finfo.Extension.ToLower() == ".txt")
{
if (txtFile1.PostedFile.ContentLength < 1024)
{
//if (!File.Exists(folderfile1))
if (Directory.GetFiles(folderfile1).Length == 0)
{
txtFile1.SaveAs(saveflFile1);
//lbFile1.Visible = true;
lbFile1.Text = "Upload status: IMSI file transfered successfully";
}
else
{
lbFile1.Text = "Upload status: Please wait until the previous file is processed";
}
}
else
lbFile1.Text = "Upload status: The file has to be less than 1 kb!";
}
else
lbFile1.Text = "Upload status: Only Text files are accepted!";
}
else
{
lbFile1.Visible = true;
lbFile1.Text = "Upload status: Please select file";
}
Use
File.Existslike this:Server.MapPathreturns a physical path on the server, so you can useFile.Existsto check if the file is present or not.