What should I blog about?

October 12, 2014 Leave a comment

Hi Everyone. I thought it’s easier for you all to tell me what I should blog about. I’ve created a Poll so please select your topic you think I should write about.

Categories: Development, Sharepoint

Using Powershell – ISE (Integrated Scripting Environment)

February 3, 2014 Leave a comment

A lot of Administrators think that PowerShell is a one-hit-wonder single command tool used to quickly perform a task which can’t be found in the GUI. They couldn’t be further from the truth. Something that very little people know, is that All Operating systems including Server OS since Windows 7 and Server 2008 has a built in PowerShell Debugger and Developer. And the best thing of all is: ITS FREE! . It’s called Windows PowerShell Integrated Scripting Environment. The description “from Microsoft” about this tool is:

 powershellise

This tool as stated above allows you to actually develop your own script-lets which will then be saved as runnable .ps1 files.

I use this tool when I want to write something that will be re-used and paramaterised.

Take note, that the tool is not installed when windows or server is installed out of the box. You have to activate it. To install it :

Open Server manager

Server Manager

Click on Features

 Features

Click on Add Features

AddFeatures

Scroll down and select Windows PowerShell Integrated Scripting Environment

Select ISE

Click Next and then Install.

You can now find the ISE under > Start > All Programs > Windows PowerShell

Powershell Location

Take note that if you are developing SharePoint related scriptlets, you have to run the 64 bit one.(The one not marked as x86) because SharePoint is a 64bit only Application. Also, always run the application as Administrator as you might run into some nasties if you don’t

The Application opens and you are ready to start writing your script:

Powershell ISE Open

More on the usage of this app in my next blog coming soon.

Using Google Charts in SharePoint

August 13, 2012 Leave a comment

Hi everyone. I recently had to build some charts for a SP Project and for me , the easiest way to get visually attracting and interactive charts, was to use Google charts. Now there are quite a few ways to get Google charts going in SharePoint (example http://code.google.com/p/googlechartsharp), so I’m sharing my way of doing it and I hope it helps someone else. Disclaimer… I am not claiming that I wrote all this code myself. Some parts are borrowed.

Ok, so here we go:

Firstly, Create a new SharePoint Solution and add a new Visual Web Part. I’m skipping instructions on this but if you don’t know how to do this, I suggest you start with some basic SharePoint development tutorials first.

Open up the User control in your visual web part (the ascx file) and insert the following code:

<div>
<!-- This line adds the Google Javascript API to your page -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>

<!-- Using the Google jsapi, we load the core charts api -->
<script type="text/javascript">
    google.load('visualization', '1', { packages: ['corechart'] });
</script>

<script type="text/javascript">
function drawVisualization() {

 // Create and populate the data table.
 // MyArrayData is your array declared on server side
 var ChartData = google.visualization.arrayToDataTable(MyArrayData); 

 //Set all your chart options here.
 var ChartOptions = {
  'title': 'Final gold medal count for 2012 olympics',
  'titleTextStyle': { color: 'black', fontName: '"Verdana"', fontSize: 12 },
  'width': 350,
  'height': 350,
  'backgroundColor': 'white',
  'chartArea': { 'width': '90%', 'height': '70%' },
  'pieSliceText': 'percentage',
  'tooltip': { textStyle: { color: 'black', fontName: '"Verdana"',fontSize:12}},
  'is3D': true
  };

    // Create and draw the visualization.
    new google.visualization.PieChart(document.getElementById('ChartAreaDIV')).
    draw(ChartData , ChartOptions );
}
google.setOnLoadCallback(drawVisualization);
</script>

</div>
<div style="border: 0 none;">
<div id="ChartAreaDIV" style="width: 350px; height: 350px;"></div>
</div>

Next up, lets get some data to render. Open the Code behind file for the ASCX, Here is the code for your code behind file:

public partial class TestGoogleChartUserControl : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DemoData demodata = new DemoData();

        //Get the Data - Use your data access layer here
        var data = demodata.GetSomeDemoData();

        //Telling the Array what it's going to hold
        Page.ClientScript.RegisterArrayDeclaration(
            "MyArrayData", "['Label', 'Value']");

        //Register items into a javascript (client side) array
        foreach (var dataitem in data)
        {
            Page.ClientScript.RegisterArrayDeclaration("MyArrayData", 
                string.Format("['{0}', {1}]", 
                dataitem.ChartItemLabel, 
                dataitem.ChartItemValue));
        }
    }
}
public class DemoData
{
    //Use your Data access layer or some other datasource
    public List<MyDataContract> GetSomeDemoData()
    {
        List<MyDataContract> data = new List<MyDataContract>();
        data.Add(new MyDataContract { 
            ChartItemLabel = "United States", 
            ChartItemValue = 46 });

        data.Add(new MyDataContract { 
            ChartItemLabel = "China", 
            ChartItemValue = 38 });

        data.Add(new MyDataContract { 
            ChartItemLabel = "Great Britain", 
            ChartItemValue = 29 });

        data.Add(new MyDataContract { 
            ChartItemLabel = "Russia", 
            ChartItemValue = 24 });

        data.Add(new MyDataContract { 
            ChartItemLabel = "Korea", 
            ChartItemValue = 13 });

        data.Add(new MyDataContract { 
            ChartItemLabel = "Germany", 
            ChartItemValue = 11 });
        return data;
    }
}    
public class MyDataContract
{
    //Just a quick data structure 
    //implemention here to make things easier
    public string ChartItemLabel { get; set; }
    public int ChartItemValue { get; set; }                
}

That’s it. Deploy your web part and it should render a nice little interactive Google pie chart:

 

Read more on Google charts here: https://google-developers.appspot.com/chart/

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: