Solved

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

Posted on 2011-02-11
4
198 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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