fileupload上传图片

来源:百度知道 编辑:UC知道 时间:2024/05/27 17:35:06
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string name = FileUpload1.PostedFile.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();

string webfilepath = Server.MapPath("/photo/" + name);
string filecontenttype = FileUpload1.PostedFile.ContentType;
if (filecontenttype == "bmp"|| filecontenttype == "gif" || filecontenttype == "jpeg")//(1)
{

try
{
FileUpload1.SaveAs(webfilepath);
L1.Text = "照片上传成功";
Image1.ImageUrl = "/photo/name";
}
catch (Exception ex)
{
L1.Text = &

测试了下没问题
[处提示运算符“||”无法应用于“string”和“string”类型的操作数]
这个一般在if里出现,比如 本该是两个等号的你只打了一个等号 就会报这个错误.

if ((filecontenttype == "bmp") || (filecontenttype == "gif") || (filecontenttype == "jpeg"))
{
.......
}