Daniel
Daniel

Reputation: 53

How to write a string in a resource file?

how to write a string in a resource file? I tried this code, but I get an error: "ArgumentException. Path contains invalid characters."

StreamReader reader = new StreamReader(Auctions_Parser.Properties.Resources.Settings);
                string content = reader.ReadToEnd();
                reader.Close();
                string ebay = "";

                if (checkBox1.Checked){ ebay = "1"; } else { ebay = "0"; }
                content = Regex.Replace(content, @"Ebay&\d", "Ebay&"+ebay);
                StreamWriter writer = new StreamWriter(Auctions_Parser.Properties.Resources.Settings);
                writer.Write(content);
                writer.Close();

Settings.txt content:

SaveFolder&C:/Desktop/
Ebay&1
Delcampe&1
BidStart&1
eBid&1
Proxy&0
OpenFolder&0
TurnOff&0

Exception indicates the first line of code (StreamReader reader = new StreamReader(Auctions_Parser.Properties.Resources.Settings);)

Upvotes: 3

Views: 4532

Answers (2)

Romil Kumar Jain
Romil Kumar Jain

Reputation: 20745

ResXResourceWriter writes resources in the system-default format to an output file or an output stream.

using System.Resources;

  // Creates a resource writer.
  IResourceWriter writer = new ResourceWriter("myResources.resources");

  // Adds resources to the resource writer.
  writer.AddResource("String 1", "First String");

  writer.AddResource("String 2", "Second String");

  writer.AddResource("String 3", "Third String");

  // Writes the resources to the file or stream, and closes it.
  writer.Close();

Upvotes: 1

Viacheslav Smityukh
Viacheslav Smityukh

Reputation: 5833

You cannot write anything into embeded resource file. You should use regular WinApp Settings instead of writing a new one.

Upvotes: 3

Related Questions