Hey all, I've got a small program to show a .nfo text file in a texbox (refer to my project here:
Creating-a-NFO-Viewer-in-Csharp-as-a-beginner[
^])
The problem at this point is that I have to sent the nfo file with my program each time! This also means I have to select the path to read the nfo from on the target client... There must be some way to use this file as resource, so it can open the file from within the .exe? Can someone help me with that?
The code that's in the spotlight for this part is this:
(on form_load)
string file_name = "C:\\Test\\DARTY.nfo";
if (System.IO.File.Exists(file_name) == true)
{
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(437);
System.IO.StreamReader file = new System.IO.StreamReader(file_name, encoding);
richTextBox1.Text = file.ReadToEnd();
file.Close();
}
else
{
richTextBox1.Text = "File not Found! :( --- Where is DARTY.nfo??";
}
How can I make this nfo file a resource?
I've tried richtclick project -> properties -> resources. Add resource (String or File).
Then in the code I tried the following, set:
string file_name = Properties.Resources.DARTY;
And edit the rest of the code accordingly.
The problem I got was: Error, cannot convert byte[] to string.
Well, I could change byte[] in the resources.designer.cs to string.
Then all seems okay, no errors. But when I run my program, no text appears in the box. I also tried disabling all converting, just directly:
richTextBox.Text = file_name;
Still no luck.
Does anybody know what I'm doing wrong, help me!
Thanks.