如何使用asp.net中的fileuploadcontrol将图像保存到我们根目录中的文件夹中 [英] how to save images into a folder in our root directory with a fileuploadcontrol in asp.net

查看:104
本文介绍了如何使用asp.net中的fileuploadcontrol将图像保存到我们根目录中的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code_behind代码
字符串imgname = UpImage.PostedFile.FileName;
字符串路径=〜/images/" + imgname;
UpImage.SaveAs(MapPath(path))
这里的UpImage是我的文件上传控件ID,图像是我的文件夹名称.但是我无法将我的图像保存到该文件夹​​中.请帮助我.

here is my code_behind code
string imgname = UpImage.PostedFile.FileName;
string path = "~/images/"+ imgname;
UpImage.SaveAs(MapPath(path))
here UpImage is my fileuploadcontrol id and images is my folder name.but i''m unable to save my images into the folder.please help me.

推荐答案

我猜这是一个权限问题.您需要为Upload(在您的情况下为"images")文件夹提供 write 权限.

它有任何错误吗?提供更多详细信息,以便可以识别出确切的问题.

您也可以检查此 msdn链接 [
I guess it''s a permission issue. You need to provide write permission to the Upload (''images'' in your case) folder.

Is it giving any error? Give more details so that exact issue can be identified.

You may also check this msdn link[^] about Uploading Files in ASP.NET. It also tells how to assign permissions to the upload folder.


只需使用

Just use

string imgname = UpImage.FileName;



代替



Instead of

string imgname = UpImage.PostedFile.FileName;



并尝试一下.

[为澄清我的答案而编辑]
UpImage.FileName仅返回文件名,例如xyz.gif
和UpImage.PostedFile.FileName返回完整路径,例如d:\ abc \ xyz.gif
因此隐藏(字符串路径=〜/images/" + imgname)将是未知位置,这就是为什么他面临错误.



and Give a Try.


UpImage.FileName returns just file name e.g. xyz.gif
and UpImage.PostedFile.FileName returns full path e.g. d:\abc\xyz.gif
so the concationation (string path = "~/images/"+ imgname) will be unknown location, thats why he is facing error.


这篇关于如何使用asp.net中的fileuploadcontrol将图像保存到我们根目录中的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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