Saturday, December 30, 2017

Implement google map inside iframe


This blog is about implementing google map in your website using an iframe. Integrating map in website has never been so easy but now we can do it in just a moment. Here are the steps on how you can use google map inside your iframe.

  • Open maps.google.com in your browser.
  • Search your map location which you want to show in your website.


For example, I searched Frankfurt,Germany



  • Click menu button --> Share or embed map





  • Then Click 'Embed Map' tab. you can find an iframe link for your map.




Thursday, December 21, 2017

Web Application Vs Desktop Application


Web Application

  • Hosted in central server.
  • Easy maintenance, customization, integration and upgrade.
  • High scalability, accessibility and sharing.
  • Less resources required for clients. A compatible browser like Chrome or Firefox is enough.
  • Platform independent. Any sort of device within the network and a browsing application is enough.
  • High dependency on network ( internet or intranet )
  • Application failure can cause whole system down and affect all clients.
  • Hosting Servers need to be powerful and hence can be expensive( also online web hosting packages can be comparatively expensive)
  • Slow application development and complicated installation/hosting.

Desktop Application

  • Application installed on local machine ( i.e on client's computer)
  • Independent of networks and also able to work offline.
  • Faster to develop and install.
  • Secured due to local application installation
  • Highly compatible for softwares regarding hardwares
  • Requires manual installation by each client
  • Scalability limited due to resources
  • Local storage and resource usage eg. hardwares and memory
  • Low data portability.


Anyway, web and desktop applications have their own pros and cons. They have their own importance based on requirements and should be developed corresponding to the situation. We
cannot just rank any one of them as first or second.

Lets suppose if your clients are world wide spreaded and you need to perform frequent communication, data sharing or need to work on common business framework, then its good to have web application.

But lets suppose you want to build an application which will access your hardware (i.e camera, microphone, graphics card etc) or lets say you don't have a powerful central server which is able to hold multiple requests from your clients, you can think of a good desktop application which will use your client's resource for the application performance and you can use your server as a central database server.

So, based on the infrastructures you have and also the business requirements from your client, you have to choose the efficient type of application.

Wednesday, December 20, 2017

Select all files inside a directory/folder (c# / .NET)


The below function implements the inbuilt libraries in .net to get all possible files inside a folder/directory. No matter how many number of folders or child folders it contains, it searches all the folders and returns a list of all file paths. It is a recursive function and hence can be a good example for the beginners to understand how recursive function works. 

        // Returns List of file paths for given search directory path.
        public List<String> SearchFiles(string searchDirectoryPath)
        {
            try
            {
                //declaration of list of full filepaths
                List<String> fileList = new List<String>();

                // fetch all files in the directory
                foreach (string file in Directory.GetFiles(searchDirectoryPath))
                {
                    fileList.Add(file);
                }

                // recursive function call for other directories inside of the current directory
                foreach (string directory in Directory.GetDirectories(searchDirectoryPath))
                {
                    fileList.AddRange(SearchFiles(directory));
                }

                //return the list of filepaths
                return fileList;
            }
            catch (Exception ex)
            {
                // throws exception if caught
                throw ex;
            }
        }


Call this function to get list of full file paths like below :


var allFiles = SearchFiles(@"D:\YourFolder");

Note : You will need  System.IO to use Directory class.

ConnectionStrings and AppSettings value from config file. ( c# / .NET)


We have faced the issues and difficulties of hard coded strings and values in our application several times. Keys, connection strings, user credentials and other dynamic settings are not supposed to be hard coded during application development. If done so, they can causes many limitations to our application and even small changes might require recompilation of application and several human hours for development and deployment.

Hence, in our application, we can put these dynamic settings in a config file and read it from there. In .net, We have a library System.Configuration to read these settings and connection strings. Below you can find the code implementation of config file as well as the library in c#.

Code implementation in config file :


<connectionStrings>
<add name="_NameOfConnectionString_" connectionString="_ConnectionString_" providerName="System.Data.SqlClient" />
</connectionStrings>

<appSettings>
    <add key="_key1Name_" value="123" />
    <add key="_key2Name_" value="abc" />
</appSettings>

To access these configuration values in our code, we can write our code as following.

Code implementation in class file :


//used namespace
using System.Configuration;

// you can access the appsettings in your code like below
string key1Value = ConfigurationManager.AppSettings["_key1Name_"];
string key2value = ConfigurationManager.AppSettings["_key2Name_"];

// you can access the connection string in your code like below
string connectionstring = ConfigurationManager.ConnectionStrings["_NameOfConnectionString_"].ToString();

Monday, December 11, 2017

Get end day of the month ( jquery / javascript)


This is a simple workout to find the end day of the month for selected date in javascript. Below is the workout on how you can do it.

Lets suppose for May 2017, you want to find the end of the month. On you javascript code you can write the following.

var _Year = 2017;
var _Month = 5;
var _date = (new Date(_Year, _Month, 0, 0, 0, 0));
var endOfMonth = _date.getDate();

endOfMonth is the end day of the month for given year and given month. You can change the year and month yourself or make it dynamic based on arguments by creating a function.

For end of month in sql check the link : http://iamfixed.blogspot.com/2017/11/get-end-of-month-in-mssql-2008-r2-2012.html

jquery ajax cache false ( MVC / c# / jquery / ajax )


Not reaching debug point on jquery ajax call



It may happen that we are using jquery ajax call and the program does not reach debug point in your controller action. This happens when ajax cache is enabled. Disabling of the cache during your ajax call can solve this problem. Below you can see an example.


$.ajax({
                url: _your_url,              
                cache: false,
                success: function (result) {
                    // _success_
                },
                error: function (req, err) {
                   // _error_
                }
            });

Enable the cache only when your ajax call returns the same result even on multiple requests. But if you need to get fresh data from controller action each time on your ajax call, better disable the cache.

Friday, December 8, 2017

Zero (or any character) Padding in javascript / jquery


This is a small manual function written in javascript to pad a certain character to a string. In practical, the string usually can a number which needs to be formatted in order to display properly. These numbers can be days, months or year for a date viewer or any number which follows a padding pattern before some operations.

    // obj : string you want to pad.
    // _lenght : length of you padded result string
    // paddingChar : the padding character which you want to add
    function Padding(obj, _length, paddingChar) {

        var str = String(obj);             
        var returnStr = "";
        if (str.length < _length) {
            for (var i = str.length ; i < parseInt(_length) ; i++) { returnStr += paddingChar; }
        }

        return returnStr + str;
    }

Call the function like this :

var result = Padding(12,5,'0');

It should return '00012'.