Wednesday, May 6, 2015

Detect browser language and other information in ASP.NET

If you just want to detect browser language you can use this

  CultureInfo ci;  
       if (userLanguages.Count() > 0)  
       {  
         try  
         {  
           ci = new CultureInfo(userLanguages[0]);  
         }  
         catch (CultureNotFoundException)  
         {  
           ci = CultureInfo.InvariantCulture;  
         }  
       }  
       else  
       {  
         ci = CultureInfo.InvariantCulture;  
       }  

if you want to get more details then use this


   string browser = HttpContext.Request.Browser.Browser;  
       string version = HttpContext.Request.Browser.Version;  
       string type = HttpContext.Request.Browser.Type;  
       string platform = HttpContext.Request.Browser.Platform;  
       string userAgent = HttpContext.Request.UserAgent;  
       string[] userLang = HttpContext.Request.UserLanguages;  
       var userLanguages = Request.UserLanguages;  


For MVC use this in your Home controller action.



C# print file on LAN Printer

If you want to print any file on network printer then you can try with this code block // Change Default Printer System.Ma...