Solved

How do I use a stored location istead of a loop in C#

Posted on 2011-02-11
4
199 Views
Last Modified: 2013-12-17
Hi,

I have the attached C# code written within my Silverlight 4.0 out of browser with elevated trust application that loops through files within the MyPictures filesystem directory and writes them to a collection for display.

How can I alter this code to display a single image file (not a collection) from a path (located within the MyPictures directory) written against a data item within my database? Currently I can pull item data (string, int bindings etc) onto my page but I don't know how to pull an image file (located in my local filesystem) from a path written against my data item. The attached code is taken from the below web page:

http://www.wintellect.com/CS/blogs/jprosise/archive/2009/12/16/silverlight-4-s-new-local-file-system-support.aspx

It displays a collection of image files from the local filesystem (MyPictures) but how can I alter this to simply show a single image file from my data source?

Thanks.
if (Application.Current.HasElevatedPermissions)
{
    string path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
 
    foreach (string dir in Directory.EnumerateDirectories(path))
    {
        TreeViewItem item = new TreeViewItem();
        item.Header = dir.Substring(dir.LastIndexOf('\\') + 1);
        DirectoryTree.Items.Add(item);
        ProcessFolder(dir, item.Items);
    }

}

Open in new window

0
Comment
Question by:aspnet-scotland
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 34871238
In database what do you have? Folder path which have image? or Image Path? or Image in bytearray?
0
 

Author Comment

by:aspnet-scotland
ID: 34871437
I have a path to the image in the db. Before running the silverlight app in question the user will download all the images required by the app into their MyPictures location.

Thanks.
0
 
LVL 12

Expert Comment

by:starlite551
ID: 34876968
Can u post the complete code here?? I think i can resolve ur issue.. :)
0
 
LVL 12

Accepted Solution

by:
starlite551 earned 500 total points
ID: 34877128
You can use this code to directly reference the image..
public Image GetImage(string path)
{
      return Image.FromFile(path); 
}

//to use above method :

Image img = GetImage("C:\Users\DefaultUser\Desktop\myImage.jpg");

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question