Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now