Zakladajac ze w resources mam 1 element, jak pobrac jego nazwe automatycznie?
File.WriteAllBytes(".\\plik.exe", Properties.Resources.plik);
System.Diagnostics.Process.Start(".\\plik.exe");
Zakladajac ze w resources mam 1 element, jak pobrac jego nazwe automatycznie?
File.WriteAllBytes(".\\plik.exe", Properties.Resources.plik);
System.Diagnostics.Process.Start(".\\plik.exe");
Że takie coś?
var firstDictionaryEntry = Resources.ResourceManager
.GetResourceSet(CultureInfo.CurrentCulture, true, true)
.Cast<DictionaryEntry>()
.First();
Debug.WriteLine("Key(Name): {0}, Value: {1}", firstDictionaryEntry.Key, firstDictionaryEntry.Value);
Mam z tym 2 bledy:
The name 'Resources' does not exist in the current context
Helper.Properities.Resources' does not contain a definition for 'firstDictionaryEntry'
?
Okej w twoim przypadku: Resources.ResourceManager
zamień na Properties.Resources.ResourceManager
.
Odnośnie drugiego pokaż kod gdzie to się wywala.
Moj program wyglada tak:
var firstDictionaryEntry = Properties.Resources.ResourceManager
.GetResourceSet(CultureInfo.CurrentCulture, true, true)
.Cast<DictionaryEntry>()
.First();
Debug.WriteLine("Key(Name): {0}, Value: {1}", firstDictionaryEntry.Key, firstDictionaryEntry.Value);
File.WriteAllBytes(".\\program.exe", Properties.Resources.firstDictionaryEntry);
System.Diagnostics.Process.Start(".\\program.exe");
a bledy wywala takie:
'System.Resources.ResourceSet' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'System.Resources.ResourceSet' could be found (are you missing a using directive or an assembly reference?) - dotyczy
.Cast<DictionaryEntry>()
i drugi:
'Helper.Properties.Resources' does not contain a definition for 'firstDictionaryEntry' dotyczy Properties.Resources.firstDictionaryEntry
using System.Linq;
Properties.Resources.firstDictionaryEntry
powinno być firstDictionaryEntry.Key
.File.WriteAllBytes(".\\program.exe", firstDictionaryEntry.Key);
Więc powinieneś wpisać tam:
File.WriteAllBytes(".\\program.exe", Encoding.Unicode.GetBytes((string)firstDictionaryEntry.Key));
Gdzie klasa Encoding
znajduje się w using System.Text;
4. Ale to wciąż nie ma sensu bo jakoś nie chce mi się wierzyć że to teraz zadziała:
System.Diagnostics.Process.Start(".\\program.exe");
Problem jest taki ze Linq odpada bo ma to dzialac pod net fram. 2
Czy da sie to zrobic?
Da się:
var dictionaryEnumerator = Properties.Resources.ResourceManager
.GetResourceSet(CultureInfo.CurrentCulture, true, true).GetEnumerator();
DictionaryEntry? firstDictionaryEntry = null;
if (dictionaryEnumerator.MoveNext())
{
firstDictionaryEntry = (DictionaryEntry) dictionaryEnumerator.Current;
}
if (firstDictionaryEntry.HasValue)
{
Debug.WriteLine(string.Format("Key(Name): {0}, Value: {1}", firstDictionaryEntry.Value.Key,
firstDictionaryEntry.Value));
File.WriteAllBytes(".\\program.exe", Encoding.Unicode.GetBytes((string) firstDictionaryEntry.Value.Key));
Process.Start(".\\program.exe");
}
Wywalalo blad dot. Resources.ResourceManager wiec dodalem Properities, zniknal ale podczas kompilacji wyskakuje okienko z "16 bit MS-DOS subsystem" "C:\DoCUME~1... The NTVDM CPU has encountered an illegal instruction. CS:053e IP:0100 ..."