Localization in ASP.NET 4.0

Hello everyone, how are you guy doing? hope all you guy doing great :) .

Recently, I have been worked on an ASP.NET project that need to be able to switch languages from English to Khmer and from Khmer to English. After google for an hour i found the way to do this and this is call Localization in ASP.NET. So i decide to write this article to share what i have been done.

Localization in ASP.NET 4 is very easy because all of your language text are store in Resource file. You just open your resource file and input your language text, then write only one line of code to switch your language. To do so follow the below steps:

  •  Start your visual studio and create new ASP.NET web application.
  • You can choose programming language you want VB.NET or C#.
  • Visual studio will generate an ASP.NET web application like image below.

  • switch to design time then drag and drop more Label and button to your default.aspx page.
  • On tools menu, click Generate Local Resource.
  • Back to your source code, you will notice that “meta:resourcekey” added to your label and button you just added above. Resource also created into your App_LocalResource folder.

  • Now on your App_LocalResource folder, select Default.aspx.resx
  • Copy and past new Resource file (Ctrl C, Ctrl V).
  • Rename your new Resource file from “Copy of Default.aspx.resx” to “Default.aspx.km-KH.resx”.
  • Remember that “km-KH” is a default culture string for Khmer Language.
  • Open “Default.aspx.km-KH.resx”, you will see your your text and you can start translate it.

  • So far so good, right? now your need to override the Culture to to switch language at runtime by add the following code.

  • That’s it. Now you can run the application and your resource file will be apply on your page.
  • The below image is my result of my project.

Next i will so you how to apply localization in WinForm application, so stay turn. :)

Happy programming…

My first LightSwitch application

LightSwitch is a new product in the Visual Studio family which is called Visual Studio LightSwitch. LightSwitch enable you to build business applications for the cloud and the desktop without focusing on writing code.

My first application using Visual Studio LightSwitch

For more information visit: http://msdn.microsoft.com/en-us/lightswitch/gg702208

Happy programming…

Pass Values Between ASP.NET Pages

It’s might useful for beginner who start working with asp.net webpage.

You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

  • Use a query string.
  • Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

  • Use session state.
  • Create public properties in the source page and access the property values in the target page.
  • Get control information in the target page from controls in the source page.

A Visual Studio Web application project with source code is available here: Download

Happy programming!

By សុភ័ណ្ឌ Posted in គ្មាន​ចំណាត់ក្រុម

Using Office 2007 Icon Gallery

Few days ago, I have been working on VSTO project related to Excel Workbook Development. Fortunately, I found a way how to use Office 2007 Icon Gallery in your office Ribbon through Visual Studio Tools for Office System (VSTO). So I decided to write this article to share with you as follow.

Office 2007 Icon Gallery

Normally, all those icons already exist when you installed Microsoft Office. To view those icons do the following:

  1. Download icon gallery viewer from here http://www.microsoft.com/download/en/details.aspx?id=11675
  2. Open Office2007IconsGallery.xlsm from your unzip folder, the following excel display.

3. Under Developer tap, you will see all excel icon gallery. Move your mouse pointer on each icon to see it’s IconID, example IconID in the image above is “SlideShowRehearseTimings”.

Visual Studio Tools for Office System (VSTO)

Now start your Visual Studio in this article I’m used Visual Studio 2008.

  1. In your Visual Studio IDE, click File menu –> New –> Project.
  2. From your New Project dialog –> Select Visual Basic/C# –> Office –> Excel 2007 Workbook.
  3. Visual Studio will generate a VSTO project for you automatically.
  4. From your Solution Explorer –> Right click on your project name –> Add –> New Item.
  5. From  Add New Item dialog –> Select Ribbon (Visual Design) –> Click Add button.
  6. After you design your Ribbon with Office Ribbon Controls in your Toolbox, your project solution might same as below image.

7. Click on button in your ribbon –> In property explorer apply your IconID above in OfficeImageId property.

8. Press F5, then excel application startup. Check your Ribbon tap, you will see your custome button and image as below:

That’s it. Now i can have an office icon in my ribbon button on Excel.

Happy programming…