Load external ressources in c#

Posted on 2009-04-20
Last Modified: 2012-05-06
For a program I need to load and assign dynamically an image.

I've something like this:

FileStream file;
file = File.Open(@"./Ressources/led_on.png", FileMode.Open);
ledON = Image.FromStream(file);

But it's search in the bin/Debug repository. Is it possible to search the ressource folder in the source folder?(or have an automatic copy?)
Question by:Nargzul
    LVL 39

    Accepted Solution

    Use an automatic copy. See the screenshot for where to do that (in the Properties window of the file). Then, on every build, whether it is release or debug, the file and its relative location in the directory structure will be copied to the build location.

    LVL 1

    Author Comment

    It's on the Ressource tab?

    Is it a way to include files corresponding to a pattern?

    Like ressources/*.(png|jpg|gif) ?(or simply ressources/*
    LVL 39

    Expert Comment


    Sorry, I don't know what you mean. But what I mean is:

    1. go to the Solution Explorer
    2. Select the Resources/myfile.png file
    3. Select the Properties window (right-click > Properties)
    4. Change the "Copy to Output Directory" setting

    that's all there is to it ;-)

    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

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    733 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

    24 Experts available now in Live!

    Get 1:1 Help Now