Tuesday, December 31, 2013

How to wrap up a website into a Windows Store app?

1. In Visual Studio 2013, create a new C# blank app project
2. Drag a WebView into your app’s XAML

3. Add following code into your MainPage.xaml.cs file
webView1.Navigate(new Uri(@"http://myevents.apphb.com/"));


Monday, December 30, 2013

How to fix 0x0000000A while install Windows 8 on Virtualbox?

Enable two options in your computer BIOS setting

+[x] Virtualization Technology
+[x] VT-d Feature

Monday, December 23, 2013

How to deal with “An error occurred on the server when processing the URL” problem for classic ASP?

This is a generic error for classic ASP hosted on IIS 7.

Go to IIS Server feature: ASP
Enable option: Send Errors to Browser

Then will find underneath real problem

Thursday, December 19, 2013

How to access Google spreadsheet by C#?

            SpreadsheetsService myService = new SpreadsheetsService("test");
            myService.setUserCredentials("AAA@gmail.com", "password");

            SpreadsheetQuery query = new SpreadsheetQuery();
            SpreadsheetFeed feed = myService.Query(query);

            Console.WriteLine("Your spreadsheets:");
            foreach (SpreadsheetEntry entry in feed.Entries)
API download link:


Data Structure Visualizations


Why use Tuple in C#?

1. To pass or return a group of values in single parameter
2. To create a temp record for a set of data without making a new class for it.

var population = Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278);
Console.WriteLine("Population of {0} in 2000: {1:N0}",
                  population.Item1, population.Item7);

Friday, December 13, 2013

What is the way to avoid memory leak and faulted state when using block to call WCF client ?

DO NOT USE using block:

catch (CommunicationException e)
catch (TimeoutException e)
catch (Exception e)
    throw; //Make sure to keep original exception 


Wednesday, December 11, 2013

How to make a MD5 hash from a string?

        public string CalculateMD5Hash(string input)
            // step 1, calculate MD5 hash from input
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);

            // step 2, convert byte array to hex string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            return sb.ToString();


What is BSON

Stand for Bin­ary JSON
It is Lightweight, Traversable and Efficient

Tuesday, December 10, 2013

How to solve Entity Framework “Invalid Column Name” problem?

Most of cases, because the schema of current database is different with original one.

Compare two database schema to find out the difference.

How to solve "LINQ to Entities does not recognize the method" problem

Linq will convert syntax into a SQL expression. If any method is not available in SQL query, will get this error.
Such as:
- NQ to Entities does not recognize the method System.Guid Parse(System.String) method, and this method cannot be translated into a store expression.
- NQ to Entities does not recognize the method 'System.String ToString()' method

Prepare value before run LINQ query..

A re-introduction to JavaScript


Thursday, December 5, 2013

How to extract text from html tages?

By HtmlAgilityPack

HtmlDocument doc = new HtmlDocument();
            string text = doc.DocumentNode.InnerText;
            text = Regex.Replace(text, @"\s+", " ").Trim();

Wednesday, December 4, 2013

AbsoluteActionLink, an extended method for HtmlHelper to render an absolute URL in ASP.NET MVC 3

using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace me.ExtensionMethods
    public static class Html
        public static MvcHtmlString AbsoluteActionLink(this HtmlHelper htmlHelper, string text, string actionName, string controllerName, object routeValues, object htmlAttributes)
            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            string baseUrl = BaseUrl(htmlHelper.ViewContext.RequestContext.HttpContext.Request, urlHelper.Content("~/"));
            var rd = CastBackTo(routeValues);
            string routelist = GetRouteData(rd);

            var htmls = CastBackTo(htmlAttributes);
            string htmlattributeslist = GetHtmlAttributes(htmls);

            var htmlstring = string.Format("{4}", baseUrl, actionName, controllerName, routelist, text, htmlattributeslist);
            return new MvcHtmlString(htmlstring);

        private static string GetHtmlAttributes(RouteValueDictionary htmls)
            string htmlattributeslist = "";
            foreach (var one in htmls.Keys)
                object value = "";
                htmls.TryGetValue(one, out value);
                htmlattributeslist = htmlattributeslist + string.Format("{0}='{1}'", one, value);
            return htmlattributeslist;

        private static string GetRouteData(RouteValueDictionary rd)
            string routelist = "";
            foreach (var one in rd.Values)
                routelist = routelist + (routelist == "" ? "" : "/") + one;
            return routelist;
        public static RouteValueDictionary CastBackTo(object ob)
            RouteValueDictionary result = new RouteValueDictionary();
            foreach (PropertyInfo property in ob.GetType().GetProperties())
                result.Add(property.Name,  property.GetValue(ob, null));
            return result;

        public static string BaseUrl(HttpRequestBase Request, string rootpath)
            var baseUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, rootpath);
            if (!baseUrl.ToLower().Contains("localhost"))
                string result = "";
                string[] baseUrlSections = baseUrl.ToLower().Split("/".ToCharArray());
                foreach (var one in baseUrlSections)
                    if (one.Contains(":") && !one.Contains("http"))
                        result = result + "/" + one.Substring(0, one.IndexOf(":"));
                        result = result + (result == "" ? "" : "/") + one;
                baseUrl = result;
            return baseUrl;

Tuesday, December 3, 2013

How to fix disappeared Immediate Windows in Visual Studio menu?

If cannot find it in View menu, then open Command Windows first by:
View -> Other Windows ->Command Window:
Then type: immed and enter.