C#中获取完整的文件路径 [英] C# Get Full File Path

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

问题描述

我有一个ASP FileUpload控件,我上传:

I have an ASP FileUpload control and I am uploading:

C:\Documents and Settings\abpa\Desktop\TTPublisher\apache-tomcat-6.0.26\webapps\ttpub\WEB-INF\classes\org\gtfs\tmp\GTFS_Rail\routes.txt

什么是C#代码使用下面的代码来抓住这个整个字符串:

What is the C# code to grab this entire string using the code below:

var pathOfCsvFile = Server.MapPath(ImportRoutes.FileName);
var adapter = new GenericParsing.GenericParserAdapter(pathOfCsvFile);
DataTable data = adapter.GetDataTable();



我知道,使用Server.Mappath需要改变。

I know that Server.MapPath needs to change.

更新:

使用 System.IO.Path.GetFullPath 给我下面的输出:

pathOfCsvFile =C:\\Program Files\\Common Files\\Microsoft Shared\\DevServer\\\ \\10.0\\routes.txt

推荐答案

您在混合了客户端和服务器的行为,这是很容易当你在本地测试做。您遇到的问题是,FileUploadControl(一般和HTML文件上传)是专门为不可以为您提供的完全的文件的路径。这将是一个侵犯隐私的行为。它的的设计,让您的是,上传自己的文件的二进制数据。具体来说,你应该查询上FileUploadControl属性:FileBytes或FileContent

You are mixing up client and server behavior, which is easy to do when you are testing locally. The issue you are having is that the FileUploadControl (and HTML file uploading in general) is specifically designed to not provide you with the full path to the file. That would be a privacy breach. What it is designed to give you is the binary data of the file that was uploaded itself. Specifically you should query the properties on FileUploadControl: FileBytes or FileContent.

只是为了进一步澄清这一问题,如果浏览器的用户实际上是一个物理上不同的机器上会发生什么Web服务器(通常情况)?将文件的在客户机上的完整路径的是您在的服务器的?

Just to further clarify the issue, what would happen if the browser user was actually on a physically different machine from the web server (the usual case)? What good would the full path of the file on the client machine be to you on the server?

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

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