开发者

ASP.NET fileupload control, can't upload files with spaces in the name

开发者 https://www.devze.com 2023-03-31 06:34 出处:网络
I have a fileupload control that I\'m using to upload file. When I upload a file with a name that has no spaces in it eg. \"example.txt\", it works fine. But when I try to upload a file with a name li

I have a fileupload control that I'm using to upload file. When I upload a file with a name that has no spaces in it eg. "example.txt", it works fine. But when I try to upload a file with a name like "example example.txt" the file does not go through. Here is my code:

<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 foll开发者_StackOverflow中文版owing error occured: " + ex.Message;
            }
        }

fuUpload.HasFile does not even return true, does anyone know why this is?

0

精彩评论

暂无评论...
验证码 换一张
取 消