0

I have hosted my asp.net web app in IIS.7 and I tried some sample code to upload the image from client machine to server using httpwebrequest post. But it could not be helped.

I have an issue accessing local machine path via browser. I know for security reason browser does not allow it to read local machine path. So how could i access without using fileuplaod control and input-file type, Is there any way to get client machine path programmatically?

my requirement is : user should not allow to select the file path. So in the code behind i want to read the particular directory image file and set value on FileStream.

Ex:like

string uploadfile = @"D:\Test.jpg";
FileStream fileStream = new FileStream(uploadfile,FileMode.Open, FileAccess.Read);

When i give path like @"D:\Test.jpg it will looking into server machine path.

I tried same Example: C# HttpWebRequest form upload

Thanks for advance

Community
  • 1
  • 1
user3017144
  • 11
  • 1
  • 3

2 Answers2

0

What you want to do, is not possible in usuable web applications.

First thing first. Your ASP.NET code is running in the server. The server don't have access to the client hard drive. They don't even know if the client have a hard drive. Imagine that I access your website with an iPad. The iPad dont' have a C:\ folder.

You could only do that, if you had your client machine inside your corporate network, and the server has some Role and/or permissions, that allowed him to reach every client machine in the network that were using your site. But even so, when a client reach the server, he don't know the network share (but you could have that info in a XML file or database table). But this would be very bad practice and a not very elegant solution for your problem/requirement.

The best and usual solution is the FileUpload control, where the client choose which file/files he wants to upload to the server.

On the other side, if you could do what you want, there were nothing that could block my access to your local files, and get access to sensitive files and upload them to the server. I could get your last vacations photos, sensitive mails, passwords, you name it. For this reason, you can't do that.

Paulo Correia
  • 616
  • 5
  • 15
0

If it not possible to upload file from client to server without fileupload control, then could please clarify what for the below link is?

http://cristiroma.wordpress.com/2010/06/08/how-to-programatically-upload-a-file-in-c-using-httpwebrequest/

rgds, thiru

  • Please ask for clarifications in comments. – Devraj Gadhavi Dec 11 '13 at 05:26
  • Please clarify the objective of the code available under the below link, is it meant for file upload from client to server (or) for different purpose altogether http://cristiroma.wordpress.com/2010/06/08/how-to-programatically-upload-a-file-in-c-using-httpwebrequest/ – Prakash Dec 11 '13 at 08:00