Solved

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

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 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