user3874443
user3874443

Reputation:

Copy embedded resource to Desktop C#

I try to copy an embedded text file to desktop. My following code doesn't work. It throws three errors.

An implicit conversion from string to byte[] is not possible]

The best overloaded method match for 'System.IO.File.WriteAllBytes(string, byte[])' has some invalid arguments

Argument '2': Conversion from string into byte[] isn't possible

string file1 = Properties.Resources.IMG_Resource_Filenames_txt.ToString();
File.WriteAllBytes(file1, NOS_File_Backup.Properties.Resources.IMG_Resource_Filenames_txt);

Does someone know how to fix? I already tried to convert my resource to byte with Convert.ToByte() ..

Upvotes: 0

Views: 305

Answers (1)

Dmitri Trofimov
Dmitri Trofimov

Reputation: 574

Your NOS_File_Backup.Properties.Resources.IMG_Resource_Filenames_txt is of string type but the File.WriteAllBytes(...) wants a byte array. This is why you get the error.

Try using File.WriteAllText(...) instead.

Upvotes: 1

Related Questions