在asp.net页面中使用fileupload控件上传图片

编程入门 行业动态 更新时间:2024-10-14 10:44:01
本文介绍了在asp页面中使用fileupload控件上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,我被困在我的代码中。 i我试图使用visual studio 2010在我的asp网页上上传图片。 只是尝试我使用此代码

Hi everyone i am stuck in my code. i am trying to upload a image on my asp web page using visual studio 2010. for just try i used this code

protected void Button1_Click(object sender, EventArgs e) { FileUpload1.SaveAs(Server.MapPath("~/image/"")); }

i在我的项目中有像webapplication的图像文件夹 - image 。 但是当我每次尝试运行代码都会出现同样的错误时,找不到路径的一部分。

i have image folder on my project like webapplication - image. but when i try to run the code everytime it gives the same error, could not found the part of path.

FileUpload1.SaveAs(Server.MapPath("~/")); FileUpload1.SaveAs(Server.MapPath("~"));

i尝试了所有这些,因为我通过互联网检查发现这些不同的方式,但没有人为我工作。我检查文件夹图像也有写入权限。 所以请任何人给我解决方案。 提前感谢。

i tried all these because i found by checking on internet these different ways, but no one work for me. i check the folder image has a write permission too. so please can anyone give me solution. thanks in advance.

推荐答案

如果您的网络表单和图像文件夹在同一目录中,请尝试以下代码 If you have your web form and image folder in same directory then try following code protected void Button1_Click(object sender, EventArgs e) { FileUpload1.SaveAs(Server.MapPath("image/"+FileUpload1.FileName)); }

您在上传图片时缺少文件名,所以我添加了 FileUpload1.FileName

If fu_data.HasFile Then Dim extension As String = Path.GetExtension(fu_data.PostedFile.FileName) Dim filepath As String = "DLR_Data/" & id & extension fu_data.SaveAs(Server.MapPath(filepath)) btn_save.Enabled = False lbl_msg.Text = "Data Inserted Successfully" End If

嗨sandeep, 谢谢。 i尝试了这个,但它不起作用。我不知道我做错了什么。 Hi sandeep, thank you. i tried this but it dose`t work. i don`t know whats wrong i did.

更多推荐

在asp.net页面中使用fileupload控件上传图片

本文发布于:2023-11-25 00:30:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627567.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   上传图片   页面   asp   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!