FileUpload.HasFile始终返回false [英] FileUpload.HasFile always return false

查看:74
本文介绍了FileUpload.HasFile始终返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在内容表的HTMLTable中使用Fileupload Control.内容页面和母版页面均不包含Updatepanel.但是,母版页具有ScriptManager.

它总是返回FileUpload.HasFile为false,PostedFile为null.在单击按钮"以上传文件之前,甚至选择了一个文件.

如何克服这个问题?

问候
Aman

Hi All,

I am using Fileupload Control in HTMLTable of Content Page. Neither Content Page nor Master page contain Updatepanel. However, Master page has ScriptManager.

It always return FileUpload.HasFile false and PostedFile is null. Even a file was selected, before clicking on Button to uploaded file.

How to overcome from this problem?

Regards
Aman

推荐答案

使用下面的C#代码.此代码永远不会返回错误或其他错误.


如果(FileUpload2.PostedFile!= null&& FileUpload2.FileName!= null)
{
byte [] imgdisp =新的byte [FileUpload2.PostedFile.ContentLength];
HttpPostedFile图片= FileUpload2.PostedFile;
image.InputStream.Read(imgdisp,0,(int)FileUpload2.PostedFile.ContentLength);

//SqlCommand cmd =新的SqlCommand(插入iu(img1)值(@ img1)",conn);

SqlCommand cmd =新的SqlCommand("pentry",con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@ pphoto",SqlDbType.Image,imgdisp.Length).Value = imgdisp;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
Use That following C# code. this code never return error or something others.


if (FileUpload2.PostedFile != null && FileUpload2.FileName != null)
{
byte[] imgdisp = new byte[FileUpload2.PostedFile.ContentLength];
HttpPostedFile image = FileUpload2.PostedFile;
image.InputStream.Read(imgdisp, 0, (int)FileUpload2.PostedFile.ContentLength);

//SqlCommand cmd = new SqlCommand("insert into iu(img1) values(@img1)", conn);

SqlCommand cmd = new SqlCommand("pentry", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@pphoto", SqlDbType.Image, imgdisp.Length).Value = imgdisp;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}


这篇关于FileUpload.HasFile始终返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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