C#.net中用FileUpload1、Button和Image1怎样做图片上传和显示? 5
展开全部
用fileupload控件可以上传,下面是我测试过的,正常上传!代码共享下:
你服务器要新建个test文件夹。
///////////////////////////////
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace SevenColorBeads.Website_SCBs
{
public partial class FileUploadImage : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnFileUpload_Click(object sender, EventArgs e)
{
String strSavePath = @"test\";
if (FileUpload_Image.HasFile)
{
String strFileName = FileUpload_Image.FileName;
String strphyApp = Request.PhysicalApplicationPath;
strSavePath = strphyApp + strSavePath ;
strSavePath += strFileName;
FileUpload_Image.SaveAs(strSavePath);
this.Label1.Text = "文件已上传到:" + strSavePath;
}
else
{
this.Label1.Text = "没有选择要上传的文件,请重新选择!";
}
}
}
}
你服务器要新建个test文件夹。
///////////////////////////////
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace SevenColorBeads.Website_SCBs
{
public partial class FileUploadImage : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnFileUpload_Click(object sender, EventArgs e)
{
String strSavePath = @"test\";
if (FileUpload_Image.HasFile)
{
String strFileName = FileUpload_Image.FileName;
String strphyApp = Request.PhysicalApplicationPath;
strSavePath = strphyApp + strSavePath ;
strSavePath += strFileName;
FileUpload_Image.SaveAs(strSavePath);
this.Label1.Text = "文件已上传到:" + strSavePath;
}
else
{
this.Label1.Text = "没有选择要上传的文件,请重新选择!";
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath("upload")+"//"+FileUpload1.FileName);
Image1.ImageUrl = "~/upload/" + FileUpload1.FileName;
}
{
FileUpload1.SaveAs(Server.MapPath("upload")+"//"+FileUpload1.FileName);
Image1.ImageUrl = "~/upload/" + FileUpload1.FileName;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询