Manikandan Sethuraju
Manikandan Sethuraju

Reputation: 2893

C# - Get Image path from Client Machine

I want to get the path of the Image which is saved in Client Machine. I know the Path and the file name of the Image. By using FileUpload i can do it, but without using fileupload is it possible to get the path of the file ??.

My Scenario is given below,

Public void ConverttoByte()
{
    //Get the image path from web.config & this image is in client machine
    string strConfig = @"C:\Manikandan\image\image1.jpg"; 
    MemoryStream MS = new MemoryStream();
    Byte[] data;
    int fiFileSize;
    System.Drawing.Image image;
    image = System.Drawing.Image.FromFile(strConfig);
    image.Save(MS, System.Drawing.Imaging.ImageFormat.Gif);
    data = MS.ToArray();
    CallDBMethod(data);
}

Here I converted the image as Byte and I called the CallDBMethod to insert this byte details to DB..

This image is available in client machine, but not in server machine..

So, how to i get this image path from client machine & how can i solve this?

Upvotes: 2

Views: 2526

Answers (2)

Shyju
Shyju

Reputation: 218702

Without the File upload control, It is not possible unless you create an Activex control (may not work in all browsers. User has to give permission to run this control).

In a web application, You can not take ( steal) any file from the user's computer without them making an action to do so( ex : selecting the file in the File Input control and clicking some upload button).

If you want the full file path of the file user selected in the file upload control, you can get by HttpPostedFile.FileName property which gives you the fully qualified name of the file on the client (Ex : C:\MySomeFolder\SomeFile.jpg).

 string fullPath=FileUpload1.HttpPostedFile.FileName

Assuming FileUpload1 is the ID of the File Upload control.

Upvotes: 2

Waqar Janjua
Waqar Janjua

Reputation: 6123

According to my knowledge it is not possible. You can't get the client's image path. The browser does not allow us to get the path. Using fileupload control you can also not get the complete path. A similar question by me How to Get complete file path using file upload control in asp.net or any other way?

Upvotes: 0

Related Questions