Archive for the ‘Misc’ Category

SharePoint Online – Setting up PowerShell

SharePoint global administrator can use the SharePoint Online Management Shell to manage the site and content.

Following are the steps we should do for that

  1. Install Windows Management Framework 3.0 – You can download it from This require a system restart
  2. Install SharePoint Online Management Shell – You can download it from

Once this is done, you can start “SharePoint Online Management Shell” and use following command to connect

Connect-SPOService -Url -credential

After connection, you can execute SPO cmdlets and work remotely.



will retrieve all sites.

Take a look at this to find the list of supported cmdlets

Categories: Misc, SharePoint Online Tags:

PHP – MySQL Insert

January 16, 2014 1 comment

After long wait I got my hands dirty with PHP and MySQL.

$dbServer = 'localhost';
$dbUserName = 'username';
$dbPassword = 'password';
$connection = mysql_connect($dbServer, $dbUserName, $dbPassword);
if(!$connection) {
		  die('Connection Failed : ' . mysql_error());

$insertStatement = 'INSERT INTO TableName(Column) VALUES("Value")';
$returnValue = mysql_query( $insertStatement, $connection );
		  die('Insertion Failed : ' . mysql_error());
echo "Data Inserted.";

Categories: Misc Tags: ,

OleDBConnection – Unspecified error

August 5, 2013 1 comment

On top of SharePoint 2010, I was trying to create an excel parser where I hit with this strange “Unspecified error”. The exception is getting generated from “OleDBConnection.Open” method

There was no inner exceptions or stack traces, which made it difficult to find the root cause. After trying out different steps like uninstalling office, restarting iis etc. eventually I resolved it by the below 3 steps

  1. Download latest Access Databas Engine Ensure to select the correct platform 32 vs 64
  2. Connection string = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=fileLocation;Extended Properties=”Excel 12.0 Xml;HDR=Yes;IMEX=1”
  3. In the web configuration file turn off Impersonation <identity impersonate=”false” />

In the connection string I am using HDR=Yes, this mean the first row in the excel file is a header row. IMEX=1 will force the excel cells to be treated as Text rather than the Excel General type which converts the data (The feature I hate most)

Congratulations 2013 Microsoft MVP!‏

April 2, 2013 2 comments

Really excited when I saw this mail on my Inbox yesterday


Dear Amal Hashim,

Congratulations! We are pleased to present you with the 2013 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in Visual C# technical communities during the past year.

The Microsoft MVP Award provides us the unique opportunity to celebrate and honor your significant contributions and say “Thank you for your technical leadership.”

Mike Hickman
Community Engagement

Categories: Misc Tags: , ,

JavaScript – Escaping quotes

While passing data through AJAX post we might want to escape quote characters. One option is to escape using JavaScript method, but this will encode the entire string. The simplest approach is using the replace method.

     data.replace(/(['"])/g, "\\$1")
Categories: jQuery, Misc Tags: ,

Windows 8 – Downloading File

Here is a snippet for downloading file using C#

    async Task<bool> DownloadFile(Uri source, StorageFile destination)
            BackgroundDownloader downloader = new BackgroundDownloader();
            DownloadOperation download 
             = downloader.CreateDownload(source, destination);
            await download.StartAsync();

            return true;
            return false;

If you want to show progress indicator, then add a ProgressBar object into the UI. And use StartAsync().AsTask(Progress)

SSIS – Daily Refresh Job

In this post I am going to explain the steps we should follow to create an SSIS package that run’s every night. The package will ensure already imported records are updated and new records are created in the destination system.

For demonstration I am assuming a source system, say CRM exists and it has a view as shown below


The job we are going to create will import this data into destination system, say Employee table as shown below


Now open SQL Business Intelligence Studio. Create new project and select “Integration Services Project” as shown below


From toolbox, drop a “Data Flow Task”


Double click to go inside the Data Flow Task and add a new OLE DB source control


Double click OLE DB Source control.


First we need to setup a new connection. For that click on the New button, enter the source database information. Once completed, select the connection. And set other properties as shown below


Next step is to add a Lookup transformation. This will help us to identify whether the record exists in the destination or not.


Before that we should add a new connection to the destination.


Now we can setup the lookup transformation as shown below


Lookup transformation by default fail if no match is found. In our case for new records this scenario will come up. To ensure new records pass through the pipeline we should set the Error Output properly.


Next, add a conditional split control


Drop the data flow arrow into conditional split control, which brings up following dialog. Select “Lookup Match Output”


Double click Conditional Split control and set following values


Now we should add the ole db destination and a ole db command controls. To “OLE DB Destination” we should select the input “New_Records” from Conditional Split. To “OLE DB Command” we should select the input “Modified_Records” from conditional split.

Make following changes to OLE DB Destination



Make following changes to OLE DB Command control





Now the package is ready for testing, hit F5 to run the package


In my next post I will show how to schedule this package to run every night.


Categories: Misc, SQL 2005, SQL 2008 Tags: ,

Windows 8 – Validate URL

Sample code for validating URL’s.

Invoke below method and pass the URL.

private async Task<bool> UriExists(string url)
        //Validate whether url has a valid uri pattern
        if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
            return false;

        //Creating the HttpWebRequest
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        //Setting the Request method HEAD, you can also use GET too.
        request.Method = "HEAD";
        //Getting the Web Response.
        HttpWebResponse response = 
            await request.GetResponseAsync() as HttpWebResponse;

        if (response.StatusCode == HttpStatusCode.OK || 
            response.StatusCode == HttpStatusCode.Forbidden)
            return true;
    catch(WebException ex)
        HttpWebResponse r = ex.Response as HttpWebResponse;
        if (r.StatusCode == HttpStatusCode.Forbidden)
            return true;
    return false;

Visual Studio 2012 – Change Themes

Download the Visual Studio Color Theme editor

Now install the downloaded visual studio extension



Now restart Visual Studio 2012. Click on Tools -> Options. Now you can choose the blue theme which is somewhat similar to Visual Studio 2010.


To change the character casing on MENU BAR


Open Registry Editor.
Navigate to “HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General”.
Add a new 32-bit DWORD “SuppressUppercaseConversion” and set value 1.


Windows 8 – Display ToolTip

Tool tips are important for a user friendly application. In this post I am going to explain how we can set tool tip for Windows Store Applications

Option #1 – Using Properties Window

In design mode, open the control properties. And set the “ToolTipService.ToolTip” property


Option #2 – By Editing XAML

In XAML mode, set control property as shown below


Option #3 – Using Code Behind

        ToolTip textUriTip = new ToolTip();
        textUriTip.Content = "New ToolTip";
        ToolTipService.SetToolTip(usr, textUriTip);