0

I want to create a resource file programmatically. I managed to do so following this link: https://msdn.microsoft.com/en-us/library/gg418542(v=vs.110).aspx

And I got this code:

ResXResourceWriter resx = new ResXResourceWriter(@".\Resources\resources.en.resx");
        resx.Close();

It's working but it wants to create the file in the "Resources" folder in "C:\Program Files (x86)\IIS Express". But I want it to create the file in the dedicated "Resources" folder in my asp.net project, how to I point to that map relatively?

2 Answers2

1

If you want it to write to a specific location I would suggest something like this

string resFilePath = ConfigurationManager.AppSettings["ResourceFilePath"];
ResXResourceWriter resx = new ResXResourceWriter(Path.Combine(resFilePath, "\Resources\resources.en.resx"));
resx.Close();

Putting the base path in the config allows you to change it when you deploy your application.

Remember that the code runs under the context of the running application though, so whatever account it runs as will require write access to your resource directory.

Mauro
  • 4,531
  • 3
  • 30
  • 56
0
  1. Create the resource file first, in the location of your choice.
  2. Add the file to the project.
  3. Depending on where the file/folder exists, VS will make either a relative or absolute reference to it
Martin
  • 2,411
  • 11
  • 28
  • 30
Prateek Gupta
  • 1,129
  • 1
  • 11
  • 24
  • But I want to let users add as many languages as they want to the site, that's why I want to add the resource files dynamically. I can't create the resource files first, I might need 1, I might need5 – Mathy Vermeiren May 19 '17 at 06:42
  • This doesn't provide an answer to the question. It should be a comment. – mmushtaq May 19 '17 at 06:52