I have an embedded resources file eg: file.exe
how to copy in directory eg: c:\
?
at click button
thanks
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);
}
}
}