【发布时间】:2014-03-11 06:34:46
【问题描述】:
我正在尝试构建一个简单的程序,我想找到一种方法将一个文件(或多个文件)嵌入到可执行文件中。
程序非常简单。我将在 Visual Studio 中使用 C# 构建一个表单。在表单上,会有几个问题和一个提交按钮。
一旦用户回答完所有问题并点击提交按钮,如果所有答案都正确,我想将文件作为奖品赠送给用户。 (文件可以是图片、视频或包含多个其他文件的 zip 文件)
我想给用户文件的方式非常灵活。它可以只是在与可执行文件相同的目录中创建此文件,或者为用户提供下载选项以将其保存在其他位置。
下面是伪代码
private void submit_Click(object sender, EventArgs e)
{
//functions to check all answers
if(all answers are correct)
{
label.Text = "Congrats! You answered all questions correctly";
//create the file that was embeded into the same directory as the executable
//let's call the file 'prize.img'
Process.Start("prize.img");
}
else
label.Text = "Some answers were not correct";
}
逻辑非常简单直接。问题是,如何将“prize.img”嵌入到可执行文件中?我会把这个程序(.exe)给一个朋友,这样他就没有任何来源,我也不能保证路径。
【问题讨论】:
标签: c# forms file embedded-resource