[英]Using File.Exists to check if a file name exists - always returning false
文件名存在且ASP.NET C#始终返回false。
我一直在尝试File.Exists
protected void Button1_Click(object sender, EventArgs e)
{
Server.MapPath("~");
string location = ("~/Uploads/");
string filename = TextBox1.Text;
string currentfile = (location + filename);
if (System.IO.File.Exists(currentfile))
{
Label1.Visible = true;
Label1.Text = "File Exists in Uploads";
}
else
{
Label1.Visible = true;
Label1.Text = "File Name Not Found";
}
}
“”“”
如果输入的文件名存在于Uploads文件夹中,我希望看到用TextBox1用户输入检查的输出
在if语句中,而不是传递相对路径,它使用server.mapth路径定位路径
if(System.IO.File.Exists(Server.MapPath(currentfile))){
}
试试这个它应该没有问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.