Monday, May 21, 2018

Angular 4 - How to detect device in browser

Its very simple and straight forward to use plugin for Angular 4 typescript as below

Use plugin https://www.npmjs.com/package/ngx-device-detector which can be added to package.json to install as reference

Include in your app.module as below

import { DeviceDetectorModule } from 'ngx-device-detector';


imports: [
      DeviceDetectorModule.forRoot()
    ],

Include in your component or service as below


import { DeviceDetectorService } from 'ngx-device-detector';

constructor(private deviceService: DeviceDetectorService) {   }

To get device info use as below in component

this.deviceService.getDeviceInfo();  //This will get all device useragent info 
this.deviceService.isTablet(); //This will get device is tablet or not
this.deviceService.isDesktop(); //This will get device is desktop or not
this.deviceService.isMobile(); //This will get device is mobile or not



Wednesday, May 2, 2018

VS - Asp.Net core application not worked and run only on fiddler

I have faced some specific issue, where .Net core project was not running on my local machine visual studio and ruins only when Telerik Fiddler ruins. It always goes to 500 error page (only for me). I have tried changing all browser proxy settings, but those not fixed my

I was searching for my Outlook automatic replies not opened and calendar schedules not shown issue, for that got fix from Microsoft as https://support.microsoft.com/en-in/help/2847833/proxy-server-causing-issues-in-outlook-with-free-busy-oof-and-mailtips, surprisingly it fixed my visual studio .net core project issue. Try below steps to reset proxy


Friday, February 16, 2018

Outlook 2016 integration to Skype for business Lync 2016

I got issue on outlook 2016 where Skype for business (Lync 2016) status for contacts not showing.

I have followed below steps and worked

1. Open RegEdit by typing in run command (WinKey + R)
2. Go to Path HKEY_CURRENT_USER\SOFTWARE\IM Providers
3. Update DefaultIMApp value as "Lync" as in screenshot below
4. Restart outlook



Ref: https://blogs.msdn.microsoft.com/rathomas/2012/12/03/outlook-2013-users-are-unable-to-see-the-presence-info-in-outlook/ 

Thursday, December 14, 2017

C# - How to merge paths with slashes in all subsequent params

To combine file paths with slashes will take care by below code

public static string MergePath(params string[] stringPaths)
        {

            for (int i = 0; i < stringPaths.Length; i++)
            {
                //To skip trim on first path
                if (i != 0)
                    stringPaths[i] = stringPaths[i].Trim().TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
            }

            return Path.Combine(stringPaths);

        }



Example:
var stringtest = Extensions.MergePath(@"c:\path\", @"\dir\file.txt");
var stringtest2 = Extensions.MergePath(@"c:\path\",@"\test\adsf\", @"\dir\file.txt");
var stringtest3 = Extensions.MergePath(@"c:\path", @"test\adsf", @"dir\file.txt");

Output:
"c:\\path\\dir\\file.txt"
"c:\\path\\test\\adsf\\dir\\file.txt"
"c:\\path\\test\\adsf\\dir\\file.txt"

Monday, July 10, 2017

IIS - Application warmup

How to warm up IIS application especially when using Entity framework

Follow below steps to enable your website always respond quickly,

- Check "Application Initialization" feature enabled in windows features turn or off



- Start Mode of Application pool set as "Always Running" in AppPool Advanced Settings
- Preload of Website should be set as "true" in Website advanced settings
- Add Application Initialization script in web.config of your application as below, You can specify valid URL which can initialize all items such as SQL DB, EF etc.,

<system.webServer>
  <applicationInitialization doAppInitAfterRestart="true" skipManagedModules="false">
      <add initializationPage="/YourUrl/YourMethodAnything" />
    </applicationInitialization>
</system.webServer>

Following these steps will solve your idle timeout application responding slow issue.

Tuesday, March 7, 2017

JavaScript - Simple Export to excel

To export excel in JavaScript without any server side techiques, we can use following steps

Used blob file saver for download https://github.com/eligrey/FileSaver.js

Step 1: Create Html Content with required styles as below

var tableHtml = '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
        tableHtml += '<head><xml><x:ExcelWorkbook><x:ExcelWorksheets>';
        tableHtml += '<x:ExcelWorksheet><x:Name>PlanFundLineup</x:Name>';
        tableHtml += '<x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet>';
        tableHtml += '</x:ExcelWorksheets></x:ExcelWorkbook></xml></head><body>';
  tableHtml += "<div><table  border='1'>" +
        tableHtml += "<thead>" +
        tableHtml += "<tr><th>" +
        tableHtml += "Header Text" +
        tableHtml += "</th></tr>" +
 tableHtml += "</thead>" +
               "<tbody>" +
        tableHtml += "<tr><td>" +
        tableHtml += "Content Text" +
        tableHtml += "</td></tr>" +
               "</tbody>" +
              "</table></div>";
        tableHtml += '</body></html>';

Step 2: Download this html content using blob

var blob = new Blob([tableHtml], { type: "application/vnd.ms-excel;charset=utf-8" })
window.saveAs(blob, "excelname.xls");