Quick Tip : List available encodings

Here is a way to list the available encodings for a version of the .NET Framework


using System.Text;

 


EncodingInfo[] encodings = Encoding.GetEncodings();

Here is a piece of code to output the encoding info in an html file (as a table for readability)


var encodings = (from e in Encoding.GetEncodings()
 orderby e.Name
 select string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", e.CodePage, e.Name, e.DisplayName)
 ).ToList();

// add html part infos
 encodings.Insert(0, "<html><head><title>Encodings</title><style>table {width:100%;} table tr:nth-child(2n){background:#ddd;}</style></head><body><h1>Encodings list</h1><table><tr><th>Code</th><th>Name</th><th>DisplayName</th></tr>");
 encodings.Add("</table></body></html>");
 File.WriteAllLines(@"c:\encodings.html", encodings);

The result for the .NET FX 4.5 :

CodeNameDisplayName
708ASMO-708Arabic (ASMO 708)
950big5Chinese Traditional (Big5)
21025cp1025IBM EBCDIC (Cyrillic Serbian-Bulgarian)
866cp866Cyrillic (DOS)
875cp875IBM EBCDIC (Greek Modern)
50221csISO2022JPJapanese (JIS-Allow 1 byte Kana)
720DOS-720Arabic (DOS)
862DOS-862Hebrew (DOS)
51936EUC-CNChinese Simplified (EUC)
51932euc-jpJapanese (EUC)
20932EUC-JPJapanese (JIS 0208-1990 and 0212-1990)
51949euc-krKorean (EUC)
54936GB18030Chinese Simplified (GB18030)
936gb2312Chinese Simplified (GB2312)
52936hz-gb-2312Chinese Simplified (HZ)
858IBM00858OEM Multilingual Latin I
20924IBM00924IBM Latin-1
1047IBM01047IBM Latin-1
1140IBM01140IBM EBCDIC (US-Canada-Euro)
1141IBM01141IBM EBCDIC (Germany-Euro)
1142IBM01142IBM EBCDIC (Denmark-Norway-Euro)
1143IBM01143IBM EBCDIC (Finland-Sweden-Euro)
1144IBM01144IBM EBCDIC (Italy-Euro)
1145IBM01145IBM EBCDIC (Spain-Euro)
1146IBM01146IBM EBCDIC (UK-Euro)
1147IBM01147IBM EBCDIC (France-Euro)
1148IBM01148IBM EBCDIC (International-Euro)
1149IBM01149IBM EBCDIC (Icelandic-Euro)
37IBM037IBM EBCDIC (US-Canada)
1026IBM1026IBM EBCDIC (Turkish Latin-5)
20273IBM273IBM EBCDIC (Germany)
20277IBM277IBM EBCDIC (Denmark-Norway)
20278IBM278IBM EBCDIC (Finland-Sweden)
20280IBM280IBM EBCDIC (Italy)
20284IBM284IBM EBCDIC (Spain)
20285IBM285IBM EBCDIC (UK)
20290IBM290IBM EBCDIC (Japanese katakana)
20297IBM297IBM EBCDIC (France)
20420IBM420IBM EBCDIC (Arabic)
20423IBM423IBM EBCDIC (Greek)
20424IBM424IBM EBCDIC (Hebrew)
437IBM437OEM United States
500IBM500IBM EBCDIC (International)
737ibm737Greek (DOS)
775ibm775Baltic (DOS)
850ibm850Western European (DOS)
852ibm852Central European (DOS)
855IBM855OEM Cyrillic
857ibm857Turkish (DOS)
860IBM860Portuguese (DOS)
861ibm861Icelandic (DOS)
863IBM863French Canadian (DOS)
864IBM864Arabic (864)
865IBM865Nordic (DOS)
869ibm869Greek, Modern (DOS)
870IBM870IBM EBCDIC (Multilingual Latin-2)
20871IBM871IBM EBCDIC (Icelandic)
20880IBM880IBM EBCDIC (Cyrillic Russian)
20905IBM905IBM EBCDIC (Turkish)
20838IBM-ThaiIBM EBCDIC (Thai)
50220iso-2022-jpJapanese (JIS)
50222iso-2022-jpJapanese (JIS-Allow 1 byte Kana – SO/SI)
50225iso-2022-krKorean (ISO)
28591iso-8859-1Western European (ISO)
28603iso-8859-13Estonian (ISO)
28605iso-8859-15Latin 9 (ISO)
28592iso-8859-2Central European (ISO)
28593iso-8859-3Latin 3 (ISO)
28594iso-8859-4Baltic (ISO)
28595iso-8859-5Cyrillic (ISO)
28596iso-8859-6Arabic (ISO)
28597iso-8859-7Greek (ISO)
28598iso-8859-8Hebrew (ISO-Visual)
38598iso-8859-8-iHebrew (ISO-Logical)
28599iso-8859-9Turkish (ISO)
1361JohabKorean (Johab)
20866koi8-rCyrillic (KOI8-R)
21866koi8-uCyrillic (KOI8-U)
949ks_c_5601-1987Korean
10000macintoshWestern European (Mac)
932shift_jisJapanese (Shift-JIS)
20127us-asciiUS-ASCII
1200utf-16Unicode
1201utf-16BEUnicode (Big-Endian)
12000utf-32Unicode (UTF-32)
12001utf-32BEUnicode (UTF-32 Big-Endian)
65000utf-7Unicode (UTF-7)
65001utf-8Unicode (UTF-8)
1250windows-1250Central European (Windows)
1251windows-1251Cyrillic (Windows)
1252Windows-1252Western European (Windows)
1253windows-1253Greek (Windows)
1254windows-1254Turkish (Windows)
1255windows-1255Hebrew (Windows)
1256windows-1256Arabic (Windows)
1257windows-1257Baltic (Windows)
1258windows-1258Vietnamese (Windows)
874windows-874Thai (Windows)
20000x-Chinese-CNSChinese Traditional (CNS)
20002x-Chinese-EtenChinese Traditional (Eten)
20001x-cp20001TCA Taiwan
20003x-cp20003IBM5550 Taiwan
20004x-cp20004TeleText Taiwan
20005x-cp20005Wang Taiwan
20261x-cp20261T.61
20269x-cp20269ISO-6937
20936x-cp20936Chinese Simplified (GB2312-80)
20949x-cp20949Korean Wansung
50227x-cp50227Chinese Simplified (ISO-2022)
20833x-EBCDIC-KoreanExtendedIBM EBCDIC (Korean Extended)
29001x-EuropaEuropa
20105x-IA5Western European (IA5)
20106x-IA5-GermanGerman (IA5)
20108x-IA5-NorwegianNorwegian (IA5)
20107x-IA5-SwedishSwedish (IA5)
57006x-iscii-asISCII Assamese
57003x-iscii-beISCII Bengali
57002x-iscii-deISCII Devanagari
57010x-iscii-guISCII Gujarati
57008x-iscii-kaISCII Kannada
57009x-iscii-maISCII Malayalam
57007x-iscii-orISCII Oriya
57011x-iscii-paISCII Punjabi
57004x-iscii-taISCII Tamil
57005x-iscii-teISCII Telugu
10004x-mac-arabicArabic (Mac)
10029x-mac-ceCentral European (Mac)
10008x-mac-chinesesimpChinese Simplified (Mac)
10002x-mac-chinesetradChinese Traditional (Mac)
10082x-mac-croatianCroatian (Mac)
10007x-mac-cyrillicCyrillic (Mac)
10006x-mac-greekGreek (Mac)
10005x-mac-hebrewHebrew (Mac)
10079x-mac-icelandicIcelandic (Mac)
10001x-mac-japaneseJapanese (Mac)
10003x-mac-koreanKorean (Mac)
10010x-mac-romanianRomanian (Mac)
10021x-mac-thaiThai (Mac)
10081x-mac-turkishTurkish (Mac)
10017x-mac-ukrainianUkrainian (Mac)

Incoming search terms:

  • scumitz koi8
  • terminal available encodings list
  • Available encodings list

Quick tip : redirect the console output to a file

In a console application, we use a lot the Console.WriteLine method.

We can redirect the output of the WriteLine method easily :


var consoleOut = Console.Out; // save the current output stream to be able to re-use it later

Console.SetOut(File.CreateText(@"C:\consoleout.txt")); // change the output stream for a file
 Console.WriteLine("a sample text"); // write some information

Console.SetOut(consoleOut); // reset the output to the console.

I want a simpler way to assign icons to my jquery ui buttons

JQuery UI has a nice widget for the buttons, problem is, imoh, that when I want to assign an icon for a button I have to do it for each button separatly.

Here is the sample from the jquery ui website :

<!doctype html>

<html lang="en">
<head>
 <meta charset="utf-8" />
 <title>jQuery UI Button - Icons</title>
 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
 <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
 <link rel="stylesheet" href="/resources/demos/style.css" />
 <script>
 $(function() {
 $( "button:first" ).button({
 icons: {
 primary: "ui-icon-locked"
 },
 text: false
 }).next().button({
 icons: {
 primary: "ui-icon-locked"
 }
 }).next().button({
 icons: {
 primary: "ui-icon-gear",
 secondary: "ui-icon-triangle-1-s"
 }
 }).next().button({
 icons: {
 primary: "ui-icon-gear",
 secondary: "ui-icon-triangle-1-s"
 },
 text: false
 });
 });
 </script>
</head>
<body>

<button>Button with icon only</button>
<button>Button with icon on the left</button>
<button>Button with two icons</button>
<button>Button with two icons and no text</button>

</body>
</html>

jquerysample

It works but I think it’s not the easiest way, I would prefer to configure the html tag with a property to say what is the icon I want.

So my solution is to use the data attribute of the element on which we want the button widget to be applied


<a href="#" class="button" data-icon="ui-icon-pencil" id="myid">my text button</a>

and in the document ready of the page

 $(document).ready(function () {

 $(".button").button({
 create: function (event, ui) {
 var icon = $(this).data("icon");
 if (HasValue(icon)) {
 $(this).button("option", "icons", { primary: icon });
 }
 }
 });
});

Basicly, when a button is created, I check if I have a data-icon property setted, and if so I use it to set the primary icon property of the button.

textbutton

I’m working with ASP.NET, so if I use WebForms I put that little piece of code in my master page, and if I’m workgin with MVC, I put the code in the _layout.cshtml file.
This way I don’t have to worry about setting the icon for each button.

But where are the icons defined ?

The example I used sooner (ui-icon-pencil) is a class of the icon set of a jquery mobile theme (you can see what’s available on the themeroller page).

If I want to define a custom icon, I do it this way

in the CSS:

.ui-icon.ui-icon-xlsx
{
 background: transparent url('images/xlsx.png') no-repeat;
}

and in the html:

<a href="#" class="button" data-icon="ui-icon-pdf">XLSX</a>

xlsxbbbb

Incoming search terms:

  • jquery ui button text after custom icon
  • jquery icons
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1839 Mqf8WGIX7s3qD7uLvutu9gxie-OQDCa2ySTINzxj-w6aCXQGfGCWEjEIbmCktHLl d596d05459a5498b90ed63678a85b223af586124&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1837 sXzSMm0piBaFa0h2fbR563ejczMlrKDL1oPxTT_O6dOncfmOyf0LBPhGNXLcw8n9 df0ee9b1e96c3a9ef3b954fa54e9438162e88b36&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1836 oaSVkdZkA6LJeq_nfXgwmY4Xb5MIxm3ZjH-vgammjutA6_Juelx3WEX9lDcPUL-4 4b3e6d12c0d23d3fb59ff29d4adbfa768ccdff51&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1827 T2kAQ2K_vzbrtvOQ_MYpJYKwHbLKQdqSDlc1xOuw0bDnKofn3-g7fIFrw5J0_fqI 6dd2d5a7913fbc9a904f7f6327264899006b5ec9&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1825 iYptg4w29Vufvl69omrtpMsn_p1Ft2Gi9i6qzd8rbbEFK2uoWIyTKfCedBSepN5J f0a97f4da9ac6ab4379bd27cc8f1ee177b72db8b&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • button(option icons not working
  • button(option icons
  • assign ui

Quick tip : avoid .Parent.Parent.Parent…..

A simple way to avoid things like this :

HiddenField ct = (HiddenField)((Button)sender).Parent.Parent.Parent.Parent.Parent.Parent.Parent.FindControl("thehiddenidentifier");

is a simple loop


Control parent = ((Button)sender);
 do
 {
   parent = parent.Parent;
   ct = (HiddenField)parent.FindControl("thehiddenidentifier");
 }
 while (ct == null && parent != null);

You can make it an extension :


public static class ControlsXT
 {
 public static Control FindInParents(this Control ctrl, string searchidentifier)
 {
 Control foundControl;
 do
 {
 ctrl = ctrl.Parent;
 foundControl = ctrl.FindControl(searchidentifier);
 }
 while (foundControl == null && ctrl != null);
 return foundControl;
 }
 }

and use it this way :


HiddenField ct = null;
Control searchedControl = ((GroupRadioButton)sender).FindInParents("thehiddenidentifier");
if (searchedControl != null && searchedControl is HiddenField)
{
ct = (HiddenField)searchedControl;
}

what do you think ? do you have any other solutions ?

Incoming search terms:

  • jquery how to avoid parent parent parent

Quick tip: list all poco’s properties and their values

Let’s say you have a poco and you want to list all its properties whith their values for debug purpose (or other purposes : logs, …)

You can write something like this :


string porperties = "property1 : " + this.property1;
porperties+="property : " + this.property2;
// ..
porperties+="propertyn : " + this.propertyn;

but it’s long and painful, plus you can forget some properties

The reflection can help us here :


string porperties = "";
 foreach (System.Reflection.PropertyInfo f in this.GetType().GetProperties())
 {
porperties += f.Name + " : " + f.GetValue(this, null) + Environment.NewLine;
 }

And if you want to be a bit clever, you create a base object and redefine the ‘ToString() method like this:


public class POCOBase
{
public override string ToString()
{
string ret = "";
foreach (System.Reflection.PropertyInfo f in this.GetType().GetProperties())
{
ret += f.Name + " : " + f.GetValue(this, null) + Environment.NewLine;
  }
  return ret;
 }
}

Then just inherit from POCOBase and call the ToString() method

The output should be something like this :

AccountID : 10
ExternalREF : 090xfe
FIRSTNAME : USER 1
LASTNAME : TEST
PHONE : 00044440000
RegisterDate : 30/09/2009 16:20:02
Remark :

I think it’s quick, easy and useful