How to work with FileUpload in a WebPage?
I have follow code in a ASP.Net Webpage:
protected void btnSend_Click(object sender, EventArgs e)
{
string imei = Request.QueryString["id"];
int imeiID = int.Parse(imei);
if (fuPicture.HasFile)
{
fuPicture.SaveAs("/Images/" + imei + ".jpg");
DAL.ImeiHandling.SavePicture(imeiID, "");
}
string code = Request.QueryString["code"];
Response.Redirect("~/UploadPicture开发者_Go百科.aspx?id=" + imei + "&code=" + code);
}
How to fill the SaveAs and how to load the path in a ASP:Image ?
Save as simply takes a file path, typically you would do something like this.
fleUpload.SaveAs(Server.MapPath("~/Images/Uploadded/new.jpg"))
or similar, to get a physical file path for the save.
Once it is saved, you can do whatever you want with it.
NOTE: You want to consider security/validation that the user really provided an image etc when doing this.
SaveAs
takes a local path (that is local to the web server) as a parameter.
You need to make sure the account that the site is running under has permissions to save to that location.
If you want to load an image from that path, you need to make sure it is mapped within the webserver and can be served from it (using a virtual directory, for example).
You can set the Image.ImageUrl
with the virtual path.
精彩评论