DanyDC
DanyDC

Reputation: 73

Write text file using resources file path

I want to write in a file which already exist in the resources:

GlobalVariable.content += "\nMicrocity";
File.WriteAllText(Properties.Resources.Favori, GlobalVariable.content);

But I have an error like:

A name of empty access path is not legal.

Upvotes: 1

Views: 1712

Answers (1)

Marc
Marc

Reputation: 3959

If you add a text file as an embedded resource, the call to Properties.Resources.Favori will return you the contents of the text file.

Therefore the File.WriteAllText() method throws this exception because the empty string is actually the file content, not the path as you expected.

To get an embedded resource file for read and write access, you can see the answer in this thread.

Upvotes: 2

Related Questions