使用 FileUpload Control 获取文件的完整路径 [英] Get full path of a file with FileUpload Control
问题描述
我正在开发一个使用 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));
如何获取完整路径?
推荐答案
尝试
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 Control 获取文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!