我有一个fileupload控件,我用它来上传文件。当我上传一个名称没有空格的文件时,例如。 “example.txt”,它工作正常。但是当我尝试上传一个名为“example example.txt”的文件时,该文件无法通过。这是我的代码:
<asp:FileUpload ID="fuUpload" runat="server" />
if (fuUpload.HasFile)
{
try
{
string filename = Path.GetFileName(fuUpload.FileName);
fuUpload.SaveAs(Server.MapPath("uploads\\" + filename));
lStatusLabel.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
lStatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
fuUpload.HasFile甚至没有返回true,有人知道这是为什么吗?