无法将文件上传到asp.net中的文件夹 [英] Unable to upload files to a folder in asp.net
本文介绍了无法将文件上传到asp.net中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将文件上传到根目录下的'Documents'文件夹。
以下代码不起作用,但文件上传到物理路径
i want to upload a file to folder 'Documents' which is in root directory.
below code does'nt work,but file is uploaded to physical path
protected void Button1_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Documents/") + filename);
}
没有使用更新面板
please帮助我。
no update panel is used
please help me with this.
推荐答案
什么物理路径?它是一个物理文件,因此必须存储在物理路径中!
What physical path? It is a 'physical' file so must be stored in a physical path!
MSDN:
MapPath方法映射指定服务器上相应物理目录的相对或虚拟路径。
The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
所以没关系... SaveAs方法将文件保存在物理路径中〜 / Documents虚拟路径点......
So it is all right...The SaveAs method will save the file in the physical path where the "~/Documents" virtual path points...
这篇关于无法将文件上传到asp.net中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文