May 31, 2011

C# HTML Minification

Questions:
- 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

Solution:
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);

References:
- 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

Error:
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'

Problem:
- 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

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

May 26, 2011

History of Adobe Media Player

Problem:
- 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?

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

May 24, 2011

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

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

Solution:
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