Tuesday, November 23, 2010

Facebook Developer Kit

Please refer the following link if you want to integrate the Facebook controls in your windows as well as web applications.


To download the Facebook developer kit use the following URL.


http://www.microsoft.com/downloads/en/details.aspx?FamilyID=CCD46762-45EC-4FBE-AD91-FC916671E734&displaylang=en


And to integrate the Facebook controls in your applications use the following URL.


http://www.stevetrefethen.com/blog/DevelopingFacebookApplicationsInCWithASPNET.aspx


Use the following URL to put the Like button of the Facebook in your applications.


http://developers.facebook.com/docs/reference/plugins/like-box

Thursday, November 11, 2010

Thursday, November 4, 2010

File upload content types

If we are uploading the file and if we want to know the exact extension of the file then, please use the following code.


public bool GetActualFileType(Stream stream)
        {
            try
            {
                using (System.IO.BinaryReader sr = new System.IO.BinaryReader(stream))
                {
                    byte[] header = new byte[16];
                    sr.Read(header, 0, 16);


                    StringBuilder hexString = new StringBuilder(header.Length);
                    for (int i = 0; i < header.Length; i++)
                    {
                        hexString.Append(header[i].ToString("X2"));
                    }


                    string FileTypeCode = GetFileTypeByCode(hexString.ToString());
                    if (FileTypeCode == "undefined")
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        private string GetFileTypeByCode(string code)
        {
            Dictionary fileheadlist = new Dictionary();
            fileheadlist.Add(".xls", "D0CF11E0A1B11AE10000000000000000");
            fileheadlist.Add(".xlsx", "504B0304140006000800000021005856");
            fileheadlist.Add(".doc", "D0CF11E0A1B11AE10000000000000000");
            fileheadlist.Add(".docx", "504B030414000600080000002100DDFC");
            fileheadlist.Add(".ppt", "D0CF11E0A1B11AE10000000000000000");
            fileheadlist.Add(".pptx", "504B03041400060008000000210036F7");
            fileheadlist.Add(".avi", "41564920");
            fileheadlist.Add(".ram", "2E7261FD");
            fileheadlist.Add(".rm", "2E524D46");
            fileheadlist.Add(".mpg", "000001BA");
            fileheadlist.Add("MPEG(.mpg)", "000001B3");
            fileheadlist.Add(".mov", "6D6F6F76");
            fileheadlist.Add(".asf", "3026B2758E66CF11");
            fileheadlist.Add(".MP4", "000000206674797069736F6D");
            fileheadlist.Add(".mp3", "49443303000000050F76545045320000");
            fileheadlist.Add(".pdf", "255044462D312E");


            fileheadlist.Add("GIF", "47494638");
            fileheadlist.Add("PNG", "89504E47");
            fileheadlist.Add("JPEG", "FFD8FF");
            fileheadlist.Add("TIFF", "49492A00");
            fileheadlist.Add("Windows Bitmap (bmp)", "424D");
            fileheadlist.Add("CAD (dwg)", "41433130");
            fileheadlist.Add("Adobe Photoshop (psd)", "38425053");
            fileheadlist.Add("Rich Text Format (rtf)", "7B5C727466");
            fileheadlist.Add("XML (xml)", "3C3F786D6C");
            fileheadlist.Add("HTML (html)", "68746D6C3E");
            fileheadlist.Add("Email [thorough only](eml)", "44656C69766572792D646174653A");
            fileheadlist.Add("Outlook Express (dbx)", "CFAD12FEC5FD746F");
            fileheadlist.Add("Outlook (pst)", "2142444E");
            fileheadlist.Add("MS Access (mdb)", "5374616E64617264204A");
            fileheadlist.Add("WordPerfect (wpd)", "FF575043");
            fileheadlist.Add("Postscript. (eps.or.ps)", "252150532D41646F6265");
            fileheadlist.Add("Quicken (qdf)", "AC9EBD8F");
            fileheadlist.Add("ZIP Archive (zip)", "504B0304");
            fileheadlist.Add("RAR Archive (rar)", "52617221");
            fileheadlist.Add("Wave (wav)", "57415645");
            fileheadlist.Add("MIDI (mid)", "4D546864");
            fileheadlist.Add("3GP", "000000146674797033677034");




            var vals = from p in fileheadlist
                       where code.StartsWith(p.Value)
                       select p;
            KeyValuePair result = vals.First();
            foreach (var i in vals)
            {
                if (i.Value.Length > result.Value.Length)
                {
                    result = i;
                }
            }
            return result.Key ?? "other";
        }




Courtesy: http://forums.asp.net/p/1554764/3829152.aspx