Solved

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

Posted on 2011-02-11
4
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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