Thursday, July 22, 2010

OData, REST and this cool program call LINQPad

I was watching this video http://azgroups.nextslide.com/odata-begins with Scott Hanselman about OData. OData is cool in itself, but what exited me most was then Scott showed this program call LINQPad http://www.LINQpad.net. LINQPad is not only a tool to build your LINQ statement in but also to execute against a data source. In Scott example, he use the http://odata.netflix.com/ as the data source and create a LINQ query that LINQPad then translator in to a REST statement, sooo cool :D

A simple walk through to query netflix.com

1) Open LINQPad and click on “Add connection”
clip_image002

2) Choose WCF Data Services as the data content and click next.
clip_image003

3) Insert the url to Netflix.com (http://odata.netflix.com/Catalog/) and click OK
clip_image004

4) Set the database to Netflix.com
clip_image006

5) Type a LINQ query like this
clip_image008

6) Select the SQL view instead of Results and wola your REST statement.
clip_image010

Saturday, July 17, 2010

PowerShell, events and file watcher

A simple script that create a file watcher on a specific folder and collect the events in a global variable.

 

function watch-folder {
    param([string]$path)
    $fileSystemWatcher = new-object System.IO.FileSystemWatcher
    $fileSystemWatcher.Path = $path
    $global:events = new-object system.data.datatable
    [void] $events.Columns.Add("Time", [datetime])
    [void] $events.Columns.Add("Full path", [string])
    [void] $events.Columns.Add("Change type", [string])
    $event = {
        [void] $events.Rows.Add([datetime]::Now, $eventArgs.FullPath, $eventArgs.ChangeType)
    }
    [void](Register-ObjectEvent -InputObject $fileSystemWatcher -EventName Created -Action $event)
    [void](Register-ObjectEvent -InputObject $fileSystemWatcher -EventName Changed -Action $event)
    [void](Register-ObjectEvent -InputObject $fileSystemWatcher -EventName Deleted -Action $event)
}
cls
watch-folder "c:\Temp"
"foobar" > c:\temp\test.txt
del c:\temp\test.txt
$global:events
get-eventsubscriber -force | unregister-event -force

Monday, July 12, 2010

patterns & practices SharePoint Guidance - SharePoint 2010 Release now Live on MSDN!!

Copy/paste from MSDN:

The following releases are designed to help solution developers and architects make the right decisions and follow proven practices when building applications for SharePoint

MSDN link : http://msdn.microsoft.com/en-us/library/ff770300.aspx

Codeplex link: http://spg.codeplex.com/

Friday, July 9, 2010

SharePint!

#SharePint the 16th of July 17 o'clock @ BrewPub http://bit.ly/uaQgJ

Wednesday, July 7, 2010

Show list items through ECMAScript and jQuery

1) Create an announcement list named "Announcements"


clip_image002


2) Create some items in the list and set some of the items Expires date to today and some to a nother date.


clip_image004


2) Through SharePoint deisnger create a new page layout.


3) Add this code to the page



<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" meta:webpartpageexpansion="full" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<SharePointWebControls:ScriptLink Name="SP.debug.js" runat="server" OnDemand="true" Localizable="false"/>
<script src="http://ajax.Microsoft.com/ajax/jQuery/jquery-1.4.2.min.js%22 type="text/javascript"></script>
<script type="text/javascript">


function GetAnnoucmentItems()
{
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var annoucmentlist = web.get_lists().getByTitle("Announcements");
var camlQuery = new SP.CamlQuery();
var camlString = '<View><Query><Where><Eq><FieldRef Name="Expires" /><Value Type="DateTime"><Today /></Value></Eq></Where></Query><RowLimit>100</RowLimit></View>'
camlQuery.set_viewXml(camlString);


this.listItems = annoucmentlist.getItems(camlQuery);


clientContext.load(this.listItems,'Include(Title, Body)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded()
{
var listItemEnumerator = this.listItems.getEnumerator();
this.listCount = this.listItems.get_count()-1;
if(this.listItems.get_count() != 0)
{
ShowAnnouncement(0);
}


}
function onQueryFailed(sender, args)
{
alert('faild');
}
function ShowAnnouncement(index)
{
if(index != 0)
{
$("#text").hide();
}
$("#text").fadeIn("slow");
var htmlString = this.listItems.get_item(index).get_item("Title") + "<br />" + this.listItems.get_item(index).get_item("Body")
$("#text").html(htmlString);
if(index < this.listCount)
{
++index
setTimeout("ShowAnnouncement(" + index + ")",3000);
}
else
{
setTimeout("ShowAnnouncement(0)",3000);
}
}
</script>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(GetAnnoucmentItems, "sp.js");
</script>
<div id="text" />
</asp:Content>


4) Create a new page based on the page layout.


clip_image006


5) And wola.


clip_image008