获取与FileUpload控件文件的完整路径 [英] Get full path of a file with FileUpload Control

查看:229
本文介绍了获取与FileUpload控件文件的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,它采用FileUpload控件的Web应用程序。我有完整的文件路径C:\\ Mailid.xls'的xls文件。我在尝试上传

I am working on a web application which uses the FileUpload control. I have an xls file in the full filepath 'C:\Mailid.xls' that I am attempting to upload.

当我使用命令

FileUpload1.PostedFile.FileName

我无法从我的系统完整的文件路径。然而,当我在另一个系统中使用上述命令它工作正常。

I cannot get the full filepath from my system. However, when I use the above command in another system it works fine.

我也试过下面的命令,但没有成功:

I also tried the following commands with no success:

   System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);
   Path.GetFileName(FileUpload1.PostedFile.FileName);
   System.IO.Path.GetDirectoryName(FileUpload1.PostedFile.FileName).ToString();
   Convert.ToString(System.IO.Directory.GetParent(FileUpload1.PostedFile.FileName));

我怎样才能得到完整的路径?

How can I get full path?

推荐答案

尝试

Server.MapPath(FileUpload1.FileName);

编辑:这个答案说明如何获取路径到服务器上的文件。它没有说明如何获取路径到客户端,这是问的问题上的文件。这个问题的答案的问题是你不能,因为现代的浏览器不会告诉你客户端上的路径,出于安全原因。

This answer describes how to get the path to a file on the server. It does not describe how to get the path to a file on the client, which is what the question asked. The answer to that question is "you can't", because modern browser will not tell you the path on the client, for security reasons.

这篇关于获取与FileUpload控件文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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