fileupload 获取选中文件的绝对路径

来源:百度知道 编辑:UC知道 时间:2024/06/09 07:34:45
你们的代码返回的都只是一个文件名(aaa.jpg),不全的,我要得到(C:\aa\ss\aaa.jpg)我只是为了获取路径而用fileupload的

那个html控件?

本来就是绝对路径

[fileupload id].FileName

----------------------------------

用html控件(客户端) 设置 name ="filepath"

然后用

Request.Form["filepath"] 返回

fileupload 获取选中文件的绝对路径,实现参考如下:
protected void BtnUp_Click(object sender, EventArgs e)
{
if (FileUpload.HasFile)
{
string savePath = Server.MapPath("~/upload/");//指定上传文件在服务器上的保存路径
//检查服务器上是否存在这个物理路径,如果不存在则创建
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
savePath = savePath + "\\" + FileUpload.FileName;
FileUpload.SaveAs(savePath);
LabMsg.Text = string.Format("<a href='upload/{0}'>upload/{0}</a>", FileUpload.FileName);