在asp.net页面中使用fileupload控件上传图片 [英] image upload with fileupload control in asp.net page

查看:78
本文介绍了在asp.net页面中使用fileupload控件上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我被困在我的代码中。

i我试图使用visual studio 2010在我的asp.net网页上上传图片。



只是尝试我使用此代码



Hi everyone i am stuck in my code.
i am trying to upload a image on my asp.net 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控件上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆