1

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?

Ceng
  • 57
  • 1
  • 9

3 Answers3

2

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.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
0

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.

Halis S.
  • 446
  • 2
  • 11
0

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

Community
  • 1
  • 1
Fus Ro Dah
  • 331
  • 5
  • 22