I want to use HttpContext.GetGlobalResourceObject for localizing strings in my application, but I am unable to create the xml file, i want to know how should i form my XML resource file so that it can be read from the HttpContext.GetGlobalResourceObject method.
The easiest way is to use Visual Studio to add and edit the resource files.
To add a global resource file to a web project, right-click the project, select Add > Add ASP.NET Folder > App_GlobalResources (if it's not already visible in Solution Explorer).
Then right-click App_GlobalResources folder, select Add > New Item..., then select the Resources File item (.RESX), type in a name and click OK.
Visual Studio will also open the RESX file after adding it to the project, and you can enter resource keys and values from there. No need to get into the XML for basic operations.
If you are interested in the XML structure you can open up the RESX file in a text editor to see the underlying XML format.
Related
I'm new to c# and I only know the basics of it. I have some data in json file and I want it to be added to my visual studio without specifying the path of it (so other people don't need to change file location when they get my program). After building the project I want the file to be automatically in the project folder somehow.
Including file in the project and moving it to the output dir automatically are different actions.
To add an existing file to project, right click your project and select "Add Existing Item". Then open file properties (right click the file => properties) and set Copy to Output Directory to Copy Always
I have a template service that uses RazorEngine to generate HTML for email sending.
I want to make it easy to add a new template to the project, meaning that I don't want to specify the file build action.
Is there a way where I still have the .cshtml file in my project with intellisense and etc. but it automatically will set their build action to Embedded Resource?
Here is a example of my project structure
Wildcard inclusions in C# project files
However, we can use wildcards when specifying these files. Here is an example that includes all .py files from a folder (and all subfolders):
EmbeddedResource Include="Python27\Lib\**\*.py"
Once you save the project file and reload it in Visual Studio, you will see that the Solution Explorer understands the wildcard and will populate with all files that match it. You can copy new .py files into the target directory and Solution Explorer will update accordingly (you need to click the “Refresh” button for this). And while it shows the results of the wildcard inclusion, it does not alter the entries in the project file unlike the behavior of the Add Files dialog.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to embed a text file in a .NET assembly?
I have a c# winforms application that use several text files.
I would like to somehow embed those files either into the exe or dlls, so that they cannot be seen by the user when the application is deployed.
Can visual studio do something like that?
With text files you can also proceed as following:
Double click your Properties -> Resources.resx file to open the resource designer.
From the first small drop down on the top, select "Files" as resource type.
Click on Add Resource -> Add Existing File... and select your text files.
Let's say that the TXT you added was called Foo.txt... you can just access it's content like so:
String foo = Properties.Resources.Foo;
Then you can also change te file names inside the resource designer and they will be automatically refactored in your code. From the Resources directory, where they are now located in your project, you can also edit them.
I just recommend you to keep their access level as internal.
Here's how I do it:
In the solution Explorer, right-click on Properies/Resources.resx.
Choose "View Designer".
You can use the "Add Resource" button, but I often just drag the file right onto the designer window.
Visual Studio will perform code generation, such that you can access your file using Properties.Resources.YourFileName.
Be wary: Visual Studio will copy your chosen file into your project's Resources folder. It will not create a link to wherever the file was originally stored.
I am creating an installer for my C# application, and I want to put a link to the configuration file into the start menu, so that users can open it for editing in notepad from the program folder in the start menu.
I seem not to be able to put a link to it however - does anyone know how to do this? (Really, I would just love to put "[targetdir]\myapp.exe.config but VS doesn't let me edit the field, only select from a file browser).
Many thanks,
Rob
I found the solution and it's pretty easy:
Add Project Output for your project in the setup project
Select Project Output from File System in left pane and go to the properties of the project output. Then add a filter *.config to remove the .config file from your project output.
Rename the app.config from your actual project to the output name that your App exe ([ProductName]) will have along with the config extension ofcourse.
Add the [ProductName].config to your setup project as a File.
Create a Shortcut to that file and add it in any setup folder desktop or program folder.
Voila.
You're all set.
Isn't the config file added in your installer? You should be able to select it when prompted for the shortcut target (the "Select Item in Project" dialog). Please note that in this prompt dialog you first need to browse to the folder which contains it (for example double-click "Application Folder").
If the config file is not added, you need to manually add it in "Application Folder". Only then you can create a shortcut to it.
Please note that Visual Studio doesn't support shortcuts to a specific file from a project output which generates multiple files. In this case you can try using a custom action which creates the shortcut through custom code.
I remember doing it in Vs2005 using as below:
File System Editor > Users Programs Menu
Add> Folder
Add file (Say Config file) point it to the its location
I have a resource file named rs.resx. In the Visual Studio designer, I can add an image to my resource file by clicking "Add resource" and specifying the path to my image file.
After adding the image, the image file itself is also copied to a folder in my Visual Studio solution named Resources. I would like all of my image files to be placed in a folder named Images instead. Is this possible?
This is a little tricky, but it is possible.
VS checks if the file added to a resource is already defined somewhere within your project. If it can't find it, it creates the folder Resources, puts a copy to the file there, adds this file to the project and puts a reference into the resource designer to this fresh copy of your file.
To avoid this behaviour you should add the file to your project before you add it into the resource file. If the file isn't somewhere within your project structure you can just create a folder, right click it, select Add file and before you click on the Add button of the OpenFileDialog, push on the little arrow next to the button and select Add as link.
Now the file resides on the place on your hdd wherever you like and the resource designer doesn't create a copy within your project file if you now add the file within the resource designer.
Maybe this little picture helps to find the Add as link button:
(source: modbusdriver.com)
That's just a subdirectory of your project directory. Your program doesn't use it at runtime, it should use the embedded resources. Anything you add to the .resx file gets copied there, not just images. But you can rename the folder if you really want to, right-click it and click Rename.
Instead of adding a .resx file to your project, I'd recommend you use the existing one. Project + Properties, Resources tab. Makes it very easy to retrieve the resource at runtime, just use Properties.Resources.Something in your code.