views:

111

answers:

1

For example, I have a flash movie in my references. How do I copy this to a location outside of the application?

+3  A: 

Assuming you have it as an embedded resource, you'd do something like:

public static void WriteResourceToDisk(Assembly assembly, 
                                       string resource,
                                       string file)
{
    using (Stream input = assembly.GetManifestResourceStream(resource))
    {
        if (input == null)
        {
            throw new ArgumentException("Resource name not found");
        }
        using (Stream output = File.Create(file))
        {
            byte[] buffer = new byte[8 * 1024];
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                output.Write(buffer, 0, read);
            }
        }
    }
}

Call it with:

WriteResourceToDisk(typeof(SomeKnownType).Assembly, 
                    "Foo.Bar.FlashFile.swf", "file.swf");

(Where Foo.Bar.FlashFile.swf is the path to the resource.)

Jon Skeet
where 'Foo.Bar.' - is a path to the resource.
Sergey Mirvoda
Yup - will update answer.
Jon Skeet
I want to suppress this feeling but don't you find it *annoying* to see someone posting a suspense question and when you ask more information, there is just dark silence! (no comments, no edits, no accepted answers)
Hemant
Yes, it's annoying. Then again, many things are annoying in life :)
Jon Skeet