3

如何在资源文件中写入字符串?我尝试了此代码,但出现错误:“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);

4

2 回答 2

3

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

于 2012-06-01T10:28:42.603 回答
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();
于 2012-06-01T10:29:29.540 回答