---
title: "Creating Image object using System.Drawing.Image.FromFile"  
description: "Creating Image object using System.Drawing.Image.FromFile"  
author: "Manoj Bhatt"  
published: 2013-04-09  
updated: 2013-04-09  
canonical: https://www.mindstick.com/forum/744/creating-image-object-using-system-drawing-image-fromfile  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# Creating Image object using System.Drawing.Image.FromFile

Hi Expert!\
I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to get the image [dimensions](https://www.mindstick.com/forum/1834/c-sharp-xaml-how-to-modify-the-dimensions-of-the-rows-and-the-columns-of-a-grid) of an image that user selects from list box. Image files are available on FTP server. I am displaying file names in \
a list box for users to select. Upon [selection](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box), I want to show the [preview](https://www.mindstick.com/forum/429/i-want-to-get-full-path-of-lt-asp-fileupload-gt-and-then-client-can-click-the-preview-button-to-see-what-file-he-here-has-uploaded) of image, for that I want to get dimensions so that I can resize it if i need to.\
I am storing [file name](https://www.mindstick.com/interview/2597/can-you-have-two-files-with-the-same-file-name-in-gac) that is linked to currently selected list item into a string variable. I know that path on the server. I am using following code to \
create the Image object, but having no luck\
try{ string dir = [Session](https://www.mindstick.com/articles/12042/session-in-c-sharp)["currentUser"].ToString(); System.Drawing.Image img = System.Drawing.Image.FromFile("~/Uploads/"+dir+"/"+fName, true); //ERROR here, it gives me file URL as [error message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration)!}catch([Exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) ex){ lbl_Err.Text = ex.Message;}Not sure what is going wrong. Any ideas?\
[Thank you in advance](https://answers.mindstick.com/qa/40482/why-was-1968-a-year-of-tension-and-turmoil-list-10-events-1-being-the-best-and-10-the-worst-thank-you-in-advance)!

## Replies

### Reply by AVADHESH PATEL

Hi Manoj!\
use **Server.MapPath** to fetch the image from the server.As follows\
System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("Uploads/"+dir+"/"+fName), true);


---

Original Source: https://www.mindstick.com/forum/744/creating-image-object-using-system-drawing-image-fromfile

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
