Image is not stored into Images folder after upload attempt. What's wrong with my code?
Here is my code:
protected void btnupload_Click(object sender, EventArgs e)
{
if (fileupload1.HasFile)
{
string fileName = fileupload1.FileName.ToString();
string uploadFolderPath = "~/Image/";
string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);
fileupload1.SaveAs(filePath + "\\" + fileName);
img1.ImageUrl = "~/Image/" + "/" + fileupload1.FileName.ToString();
lblimg_name.Text= fileupload1.FileName.ToString();
}
}
If you are using <asp:FileUpload>
, try this:
Or Describe in detail
string strFileName = "fileName";
string strFileType = System.IO.Path.GetExtension(fileupload1.FileName).ToString().ToLower();
fileupload1.SaveAs(Server.MapPath("folderpath" + strFileName + strFileType));
change
img1.ImageUrl = "~/Image/" + "/" + fileupload1.FileName.ToString();
to
img1.ImageUrl = "~/Image/" + fileupload1.FileName;
you have additional "/"
in your path
Try this code..
protected void btnupload_Click(object sender, EventArgs e)
{
if (fileupload1.HasFile)
{
string fileName = Path.GetFileName(fileupload1.PostedFile.FileName);
fileupload1.PostedFile.SaveAs(Server.MapPath("~/Image/") + fileName);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.