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
2009-06-26 09:02:58
where 'Foo.Bar.' - is a path to the resource.
Sergey Mirvoda
2009-06-26 10:20:59
Yup - will update answer.
Jon Skeet
2009-06-26 11:06:18
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
2009-06-26 11:22:15
Yes, it's annoying. Then again, many things are annoying in life :)
Jon Skeet
2009-06-26 11:38:45