如何提取临时文件C# [英] How to Extract Temporary file C#

查看:98
本文介绍了如何提取临时文件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手我的程序包含两个.swf文件我把它们放在我的资源中,我想将它们从资源中提取到临时文件夹,当我打开程序并在关闭程序时将其删除我希望现在你清除我的问题





[更新:]将两个文件解压缩到tempory文件夹并使用它们并在程序关闭时删除[/ update]

i''m New to C# my program contain two .swf files i put it them my Resources and i want to extract them from Resources to temporary folder when i open the program and delete them when close the program i hope now you clear my question


[Update:]extract two file to tempory folder and use them and delete when the program close[/update]

推荐答案

哦,对 - 这更有意义!



您添加的每个文件嵌入式资源可通过Properties.Resources获得。因此,例如,如果您将名为MyYouTube.flv的flv文件作为嵌入资源添加到资源中:

Oh, right - That makes a bit more sense!

Each file you add as an embedded resource is available via the Properties.Resources. So, if for example you add a flv file called MyYouTube.flv to your Resources as an embedded resource:
object res = Properties.Resources.MyYouTube;

如果查看对象,它将是一个字节数组,因此您可以保存它:

If you look at the object it will be an array of bytes, so you can just save it:

fileName = Path.GetTempFileName();
File.WriteAllBytes(fileName, (byte[] res);

如果您将文件名保存在class,然后处理FormClosing事件,你可以在完成后删除临时文件。

If you save the file name in your class, then handle the FormClosing event, you can delete the temporary file when you are done.


这篇关于如何提取临时文件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆