3

I have a bunch of database entries for use as resources in a web application.

I would like to put these entries into a resource (.resx) file, but there are over a thousand db entries and I would like to write a quick program to create the .resx file.

How can I create this file? I've looked at the ResourceWriter class, but when I tried that it corrupted my .resx file.

Can anyone provide any ideas or code samples? Any help would be appreciated!

5
  • 1
    Are you sure that you need a resx file? You can add resources as "plain" files, the only difference would be that you wouldn't get to access them through nicely-named variables. Commented Sep 5, 2012 at 21:48
  • @dasblinkenlight - good point, although I really would like to access them through strongly typed variables. I've got it all going now, just need to create that .resx file. Commented Sep 5, 2012 at 21:51
  • 1
    I don't think that the resx file alone gets you your strongly typed variables. Along with your Resources.resx file, Visual Studio automatically code-gens a file called Resources.Designer.cs that does all of the strong-typing for you. Even if you get your resx file in place, you'll still have to code-gen this file. If you're able to code-gen the file (the hard part) then you might as well include the plain files and have the code-genned part target those. Commented Sep 5, 2012 at 22:59
  • 1
    resX files are just Xml files with a certain schema. Commented Sep 5, 2012 at 23:13
  • Thanks, good to know, that could also be an easy way to generate. Commented Sep 6, 2012 at 5:23

1 Answer 1

2

Just use a plain StringBuilder to construct the xml content you need and then save it to the file.

Sign up to request clarification or add additional context in comments.

4 Comments

I thought about that, but initially dismissed it since I thought the PublicKeyToken was somehow unique to each entry.
I'll end up doing this way, but seems kind of ghetto, sure there isn't a cleaner way?
I think it a KISS way of doing things
True, when I think about it, would end up being about 10 lines of code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.