Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Get Full File Path

Tags:

c#

asp.net

gtfs

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

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();

I know that Server.MapPath needs to change.

UPDATE:

Using System.IO.Path.GetFullPath gave me the below output:

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

like image 928
balexander Avatar asked Mar 15 '26 14:03

balexander


1 Answers

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.

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?

like image 119
Kirk Woll Avatar answered Mar 18 '26 04:03

Kirk Woll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!