1

I don't know why I can't get this to work, I have found lots of answers on google but none of them seem to work for me.

My program requires a file on disk called "wordlist.txt" at runtime, in the same directory as the executable. So I have in my constructor code to check whether it exists, and if not to create it by copping it from the embedded resource

public Form1()
{
    InitializeComponent(); 

    if (!File.Exists("wordlist.txt")) 
    {
        byte[] ba = File.ReadAllBytes(Properties.Resources.wordlist);
        File.WriteAllBytes("wordlist.txt", ba); 
    }
}

It tells me I have illegal characters in my path though.

Scott Smith
  • 1,823
  • 17
  • 15
Mein Code
  • 15
  • 1
  • 3
  • What is the value of `Properties.Resources.wordlist`? `File.ReadAllBytes` takes a filename as its first parameter. – M.Babcock Feb 01 '12 at 00:47
  • wordlist is just a .txt file that I have added as an emberred resource. It passes the syntax check like that and if I type "byte[] ba = File.ReadAllBytes(Properties.Resources.wordlist);" it doesn't – Mein Code Feb 01 '12 at 00:51
  • You're probably looking for something like the answer to this related question: http://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file – M.Babcock Feb 01 '12 at 00:54
  • And you can check the name of your resource with `Assembly.GetExecutingAssembly().GetManifestResourceNames()` – L.B Feb 01 '12 at 01:00

2 Answers2

2

I think your are storing the default word list as a resource. If you are, you probably need something like,

if (!File.Exists("wordlist.txt"))
{
    File.WriteAllText("wordlist.txt", Properties.Resources.wordlist);
} 
Phil Bolduc
  • 1,586
  • 1
  • 11
  • 19
-1

have you tried using the full path like @"c:\worldlist.txt" instead of just the filename?

c0deNinja
  • 3,956
  • 1
  • 29
  • 45