0
は、リソースへの実行可能ファイル(.exeファイル)を追加し、プログラム実行ファイル(.exe)をプログラム上でリソースに追加する方法はありますか?
のVisual Studio 2015 - ビジュアルC# - Windowsのフォームアプリケーション - .NET Frameworkの4.6.1私は実行可能ファイルを追加するときに間違って何
(.exe)をリソースに追加しますか?
リソースはlistBoxに他のリソースとともに表示されず、エラーは戻されません。リソースの名前はリストボックスに正しく読み込まれますが、新しいリソースを追加する際に間違いがなければ問題になります。
private void button1_Click(object sender, EventArgs e)
{
//Add an .exe file to resources
byte[] xa;
xa = FileToByteArray(@"C:\Users\" + System.Environment.UserName + @"\Downloads\executable.exe");
var str = System.Text.Encoding.Default.GetString(xa);
using (ResXResourceWriter resx = new ResXResourceWriter(@".\Resources.resx"))
{
resx.AddResource("myExe", xa);
}
//
//Add the name of existing resources into a listBox
ResourceManager mgr = Resources.ResourceManager;
ResourceSet set = mgr.GetResourceSet(CultureInfo.CurrentCulture, true, true);
foreach (DictionaryEntry o in set){listBox1.Items.Add((string)o.Key);}
mgr.ReleaseAllResources();
//
}
//Converts a file to a byte array
public byte[] FileToByteArray(string fileName)
{
byte[] buff = null;
FileStream fs = new FileStream(fileName,FileMode.Open,FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes = new FileInfo(fileName).Length;
buff = br.ReadBytes((int)numBytes);
return buff;
}
これはあなたの質問には答えませんが、[File.ReadAllBytes](https://msdn.microsoft.com/en-us/library/system.io.file.readallbytes.aspx)を参照してください。 –