如何在资源文件中写一个字符串?

时间:2012-06-01 10:17:12

标签: c#

如何在资源文件中写入字符串?我尝试了这段代码,但是我收到一个错误:“ArgumentException。路径包含无效字符。”

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内容:

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

异常表示第一行代码(StreamReader reader = new StreamReader(Auctions_Parser.Properties.Resources.Settings);

2 个答案:

答案 0 :(得分:3)

您无法在嵌入式资源文件中写入任何内容。您应该使用常规的WinApp设置而不是编写新的设置。

答案 1 :(得分:1)

ResXResourceWriter将系统默认格式的资源写入输出文件或输出流。

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();