May 31, 2011

C# HTML Minification

- Is there any code which input the html source of a page and it will minify the code?
- A solution for Text Compress without used of GZip for...
- Minifies given HTML or XML source by removing extra whitespaces, comments and other unneeded Characters without breaking the content structure
- Minify HTML (or XHTML), and any CSS or JS included in your markup
- Compressing and Minifying HTML Markups

I hope this helps.
/// Solution A
html = Regex.Replace(html, @"\n|\t", " ");
html = Regex.Replace(html, @">\s+<", "><").Trim();
html = Regex.Replace(html, @"\s{2,}", " ");

/// Solution B
html = Regex.Replace(html, @"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}", "");
html = Regex.Replace(html, @"[ \f\r\t\v]?([\n\xFE\xFF/{}[\];,<>*%&|^!~?:=])[\f\r\t\v]?", "$1");
html = html.Replace(";\n", ";");

/// Solution C
html = Regex.Replace(html, @"[a-zA-Z]+#", "#");
html = Regex.Replace(html, @"[\n\r]+\s*", string.Empty);
html = Regex.Replace(html, @"\s+", " ");
html = Regex.Replace(html, @"\s?([:,;{}])\s?", "$1");
html = html.Replace(";}", "}");
html = Regex.Replace(html, @"([\s:]0)(px|pt|%|em)", "$1");

/// Remove comments
html = Regex.Replace(html, @"/\*[\d\D]*?\*/", string.Empty);

- Is there a better approach to minify html generated from aspx page
- Efficient stylesheet minification in C# 
- Follow up to Additional CSS minifying regex patterns
- Improve ASP.NET Performance - CSSmin

May 29, 2011

Nullable String

The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'

- I have a function that I want to pass data that gets data from ...
- What's C# problme with nullable string ...
- Why no support for nullable string in C#
- C# have a problem with passing nullable string ...
- public void test(string? x){} has ERROR
- public void test(Nullable x){} has ERROR

:-D System.String is a reference type and it is nullable. :-)

May 26, 2011

History of Adobe Media Player

- How do i delete all my personal videos in Adobe Media player?
- Where is file history in Adobe Media Player?
- How to clear history of Adobe Flash Player?

It's so simple. Go to below folder and delete or rename it ... ;-)
C:\Users\{YOUR USER}\AppData\Roaming\Adobe\Adobe Media Player
C:\Users\Administrator\AppData\Roaming\Adobe\Adobe Media Player

May 24, 2011

Modifying a 'method' which contains a query expression will prevent

Modifying a 'method' which contains a query expression will prevent the debug session from continuing while Edit and Continue is enabled.

If did you add a LINQ code then you have no solution.
I'm serious and you can find the answer of microsoft out here

May 10, 2011

String was not recognized as a valid DateTime

The message of exception is "String was not recognized as a valid DateTime."

- I am trying to convert my string formated value to date type with DateTime.ParseExact but ...
- I get the error saying "String was not recognized as a valid DateTime" when I used of ParseExact ...
- ... in some value as "9/7/2008 13:00:00" when im going to set startdate it throw was not recognized as a valid DateTime and ...

The DateTime.ParseExact have not any problem and the orginal problem comes from us thus you attention to String of Formatx
EXAMPLE: the string format for "02/Dec/2007:14:15:40 -08:00" is
WRONG: dd/MMM/yyyy:hh:mm:ss zzz
RIGHT: dd/MMM/yyyy:HH:mm:ss zzz

Did you got the problem source! It comes from (hh) and because the hour is greater than 12 need the (HH). Ok, look at again to the StringFormat and debug it again ;-)