fileupload postedfile始终不为null [英] fileupload postedfile is always not null

查看:106
本文介绍了fileupload postedfile始终不为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:FileUpload ID="FileUpload1" runat="server" onchange="fileCheck(this);" />




if (FileUpload1.PostedFile != null)
            {
                fileName1 = FileUpload1.FileName;
                filePath1 = Server.MapPath("Image/" + System.Guid.NewGuid() + fileName1);
                FileUpload1.SaveAs(filePath1);
                int getPos = filePath1.LastIndexOf("\\");
                int len = filePath1.Length;
                getPath1 = filePath1.Substring(getPos, len - getPos);
                pathToStore1 = getPath1.Remove(0, 1);
            }



我在我的项目中使用fileupload但是如果阻塞它总是进入内部,但我不是通过fileupload选择任何东西。


I am using fileupload in my project but it always goes inside if block, but i am not select anything by fileupload.

推荐答案

嗨试试这个



Hi try like this

if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
        {
            string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);











or

if(FileUploadControl.HasFile)
{
}


这篇关于fileupload postedfile始终不为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆