Click to See Complete Forum and Search --> : how do i retreive images from system directory


umarani
07-11-2006, 04:30 AM
hi, i am working in c#asp.net.
i stored my images in system directory.
i have one text box and one html image box and one button in my form. my need is if i type image name and click retreive button that image has to be shown in my image box.
actually i stored my image in my c:directory.
so please tell me how to retreive my images from system directory using its name.give example coding to do that.

Sync
07-11-2006, 05:35 AM
actually i stored my image in my c:directory.
What I like to suggest is that Image File should be stored in any folder of ur web project directory. I won't say that it can't be done.. It can be done. but there are a lot of thing concerned with that.. i.e: security issues.

Can I suggest other solution for you?
Suppose:
Let's say .. Your web project is located under "C:\Inetpub\wwwroot\MyProject".. and Your Image Folder is under "C:\Inetpub\wwwroot\MyProject\Images".

So,

Step 1.
You should store the image path in web.config.
eg:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="PicRootPath" value="~/PICStore/"/>
</appSettings>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off" />
</system.web>
</configuration>

Step II,
~ Loading the path of Image Folder which is stored in web.config. (maybe. you can use this coding in Page_Load)

/// <summary>
/// The constructor will load the path for the root folder for the pictures
/// </summary>
public string pathLoader()
{
Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");
if(0<rootWebConfig.AppSettings.Settings.Count)
{
KeyValueConfigurationElement picRootElement = rootWebConfig.AppSettings.Settings["PicRootPath"];
if(null!=picRootElement)
{
return picRootElement.Value;
}
}
}

Step III
string picRootRealPath = pathLoader();
if (Directory.Exists(picRootRealPath)){
foreach (string iPhotoName in Directory.GetFiles(galleryPath,"*.JPG")){
// string photoName = iPhotoName.Substring(iPhotoName.LastIndexOf("\\") + 1);
//photo path
}
}


Note: Actually, it's just some notes that I make for ur probs.. .. You might need to customize the coding as you want.

Ref: http://www.codeproject.com/useritems/Nileblitz_Photo_Gallery.asp

Hope you may find it useful...