I have an embedded resources file eg: file.exe how to copy in directory eg: c:\?
at click button
thanks
Asked
Active
Viewed 1.8k times
13
Neil Knight
- 47,437
- 25
- 129
- 188
mediolanum
- 139
- 1
- 2
- 5
1 Answers
25
You can use Assembly.GetManifestResourceStream to get a stream to read your resource from. Then just copy it to a FileStream. If you're using .NET 4, you could use Stream.CopyTo to make that easy:
private void CopyResource(string resourceName, string file)
{
using (Stream resource = GetType().Assembly
.GetManifestResourceStream(resourceName))
{
if (resource == null)
{
throw new ArgumentException("No such resource", "resourceName");
}
using (Stream output = File.OpenWrite(file))
{
resource.CopyTo(output);
}
}
}
Pieter Müller
- 4,573
- 6
- 38
- 54
Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194