简体   繁体   中英

Asp.Net C# Getting Full Path of a File

I am building a web application using WCF. I need to full path of a file to open and upload it to web service. What I am doing is first opening a file by its full path, then take stream of it and finally upload it to service. My code is below

string Path = Server.MapPath( FileUpload1.PostedFile.FileName);

System.IO.Stream fileStream = File.OpenRead(@Path);

I can't get full path of the file for security reasons.

How can I read the file that users select?

Server.MapPath(FileUpload1.FileName) is the path to a file on the server. You cannot get the full path of the client machine of the file Using the FileUpload .

There is no need for the full client path to access it. You can use the FileBytes property in order to read the contents of uploaded file.

As others have already suggested there's no reason you need the file path to the client in order to save a file on your server. In the case you need some clearer explanation for this, then please refer to these answers:

https://stackoverflow.com/a/3077008/2196675

https://stackoverflow.com/a/1130718/2196675

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM