loads of useful information, examples and tutorials pertaining to web development utilizing asp.net, c#, vb, css, xhtml, javascript, sql, xml, ajax and everything else...

 



Advertise Here
C-Sharpener.com - Programming is Easy!  Learn Asp.Net & C# in just days, Guaranteed!

Setting up Castle Windsor IoC (Inversion of Control) aka Dependency Injection

by naspinski 10/4/2009 10:55:00 AM

it can be a bit confusing getting this thing running

Dependency Injection is the new big thing, and I am late on that bandwagon. But I recently began using Castle Windsor while learning ASP.NET MVC through reading Pro ASP.NET MVC Framework which is a fantastic book.

Anyway, setup can be a little pain to go through, and is no longer exactly as written out by the book, so here is a quick and simple guide:

download/reference

  • Visit the Project Page and look for the MicroKernel/Windsor project, download the latest stable version (it was 2.0.0 while writing this).
  • Copy the dlls to your bin or register them in your GAC.
  • Reference the following libraries:
    • Castle.Core
    • Castle.DynamicProxy2
    • Castle.MicroKernel
    • Castle.Windsor

alter your web.config

Add in the following inside the <configSections$gt;

<section name="castle" type="Castle.Windsor.Configuration.AppDomain. CastleSectionHandler, Castle.Windsor" />


Add this right before your <system.web>

<castle><components></components></castle>


that's it

That's all it takes, your Castle Windsor should now be running.

Currently rated 3.0 by 4 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

asp.net | mvc

Getting the Sheet Name(s) from an Excel Document with OleDb

by naspinski 9/22/2009 10:21:00 AM

users name their sheets all sorts of crazy things, but sometimes, I want to be able to get the sheet names regardless of what they are named

Considering that I already have my ConnectionString strC set up to access my Excel file, I can just use the GetOleDbSchemaTable method like this:
DataTable dtS;
using (OleDbConnection c = new OleDbConnection(strC))
{
  c.Open();
  dtS = c.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, 
    new object[] { null, null, null, "TABLE" });
  c.Close();
}

Now dtSchema holds the sheet names (in alphabetical order). To get them out:
foreach(DataRow row in dtS.Rows)
  Console.WriteLine(row.Field<string>("TABLE_NAME"));

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

c# | excel

Slick-Ticket v2.0 Released

by naspinski 9/20/2009 1:24:00 PM

Many improvements across the board, mostly behind the scenes

I am proud to say that I have released version 2 of my open-source trouble-ticketing/help desk system Slick-Ticket. I wasn't initially planning on making a new release, but the program has become suprisingly popular with over 3,000 downloads and an actual (small) community of users which is great!

You can download Slick-Ticket v2.0 if you have never used it before. If you have already been using a previous version, you will need to replace your existing code with the patching program, run it, then download version 2. It does a few database modifications to cleanup the lack of seperation of markup/db which was done very poorly in a rush of the first version. As with any upgrade, I highly recommend you backup prior to running this upgrade!

improvements

  • Broke the dbi.cs class up into more discreet classes
  • Renamed many methods properly
  • Removed (non-user-added) markup from any of the database fields
  • Moved some markup from the code-behinid to the .aspx pages
  • Globalized and ready for translation
  • Added ability to possibly delete attachments/comments/tickets in the future
  • Introduced some more dependency injection
  • Code is now much more robust!

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

asp.net | c# | linq-to-sql | my projects

Convert Month Integer into a Month Name in Asp.Net

by naspinski 9/17/2009 6:38:00 AM

turn 12 into 'December', 1 into 'January', etc.

Simple line of code that makes life easy, it's even culture sensitive:
CultureInfo.CurrentCulture.DateTimeFormat
  .GetMonthName(intMonth);

Currently rated 4.3 by 3 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

asp.net | c#

Translating an Asp.NET site to Another Language Using .resx Files

by naspinski 9/15/2009 10:35:00 AM

translating the .resx files to another language does not require any programming knowledge at all

Translating a properly globalized site in asp.net is simple and does not require the least bit of development knowledge... which is good, because most developers I know barely have a grasp on their own [non-programming] language. This post should probably come after one on how to globalize your asp.net site, but I have an urgent need to explain how to do this first (someone has volunteered to translate my open-source project Slick-Ticket to Spanish; thanks Victor!).

how does it work?

First of all, you should understand how this actually works, it may make it easier. Every page in a site has access to two types of resources (when I say resources here I am referring to strings, words or phrases): Global Resources, and Local Resources - these resources are held in .resx files. Global Resources are commonly used resources that all pages can see, and Local Resources are resources that only a specific page can see. Each language/dialect has a specific code, which you can see here: Language Codes (you can see your default setting in your browser options, for IE, check Tools->Internet Options->Languages). Each page then has place-holders where it will substitute a specific language's resource if it is available. For example, if your browser's settings are set to Mexican Spanish (es-mx) and you are trying to view example.aspx, asp.net will look for the example.aspx.es-mx.resx file to fill in the text. If that file is not present, it will default back down to the default resx file which is example.aspx.resx.

simple enough, how do I edit them?

.resx files are just xml files, and can be edited in a text editor, but that can be very confusing and error prone as there is no syntax and/or structure checking. I recommend you use a program such as Visual Studio if you have it, or Visual Web Developer (free) if you don't; alternatively, there are a few more options such as Mads Kristensen's .NET resource editor application for .resx files, and Resx Editor on SourceForge.

Once you have your editor, just go through and edit the column to be translated, and *ONLY* that one column, messing with the key/name field will break the translation completely.

folder structure

This is the only part that might be a bit confusing. Each folder that contains .aspx, .ascx, etc. files (files with words to be translated) will have their own App_LocalResources folder, and in this folder, there will be a corresponding *.aspx.resx file for each file. Also, any additional languages will be held in a folder with the language abbreviation, and a corresponding file for each file as well. For example, in the admin folder shown here, you can see that it has it's own App_LocalResources folder, in that folder is each corresponding default (in blue) .resx file and there is a folder for each additional language. Here you see the en-us folder (English - United States) and in that you see the same .resx file, but each is named *.en-us.resx (in red) instead of just *.resx. This is the same for each folder, so you will see many App_LocalResources folders. If you forget to change any of them, it will be pretty apparent when you run the program and a lot of stuff does not match up.

Then there is the App_GlobalResources folder in the root; the same thing applies here, just do the same and translate the value column.

Remember that asp.net will first look for your desired language, and use it if it is there, if not, it will drop down to the default.

a couple notes

A couple things to keep in mind, if you see any html markup (not the best practice, but sometimes necessary), remember this:

<do_not_edit>edit_this</do_not_edit>


Also, if you see brackets with a number in them (i.e. {0}, {2}, etc.), be sure to leave those, the developer is using that as a word placeholder.

that's it

Now, as long as it is available, your users will see your site in their preferred language. It is a bit tedious to translate, but much easier than walking through the markup and screwing things up that way. Also, if a resx file is ever missing, it will not error out, it will simply use the default for any parts that are not available.

Currently rated 4.8 by 4 people

  • Currently 4.75/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

asp.net | tutorials