Thursday, February 21, 2013

How to develop Android apps by C#?

http://xamarin.com/monoforandroid

Wednesday, February 20, 2013

Can you Restore SQL Server 2012 backup to a SQL Server 2008 database?

No. Error message: Specified cast is not valid. (SqlManagerUI)
You can restore 2008 to 2012, but not backward.

Tuesday, February 19, 2013

How to Cache image in IHttpHandler?

1. Check header If-Modified-Since, if found, then return Not modified
2. Set Last-Modified header in response header
    public class GetImage : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var If_Modified_Since = context.Request.Headers["If-Modified-Since"];
            if (If_Modified_Since != null)
            {
                context.Response.StatusCode = 304;
                return;
            }
            context.Response.BinaryWrite(Image2Byte(CreateBitmapImage("Hello World")));
            context.Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0)); 
            context.Response.Cache.SetLastModified(System.DateTime.Now);
            context.Response.ContentType = "image";
        }
    }

How to solve "This operation requires IIS integrated pipeline mode."

Change from:
context.Response.Headers.Add("header", "header");
To
context.Response.AddHeader("header", "header");

Friday, February 15, 2013

How to extract Javascript from html source by HtmlAgilityPack

            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(html);
            var scriptList = htmlDoc.DocumentNode.Descendants()
                .Where(n => n.Name == "script" );