Starting Silverlight Development with Samples


I was never a Silverlight Developer but after spending some time on SharePoint 2010 and watching the SL Dialogs all way around I decided to play with it for a moment. I never knew how SL Works. Just saw couple of vidoes and some SharePoint Sessions talks on Silverlight and SharePoint Integration that also shows SharePoint Client OM. So After spending some time on Hello Worlds I search on SL Toolkit and I am so happy that I found this link. When you see a running examples of the controls it is so easy to start development. The Link to the sample is given below. some of you are already experts so dont feel tough on me. I am just a begginer.

http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html

but I have completed web part that displays pending tasks to users which prooved quite handy in my situation as I was able to develop it in just 2 days. I will try to post the code soon.

I must say that Silverlight is simply “AWSOME”.

Advertisements

Client Object Model Basic Example – CAMLQuery


I was able to make a nice CAML Query Work in my Silverlight application so though it might be worth posting it over here as it might help some one. It is a query to read all items assigned to me or the group I am part of and the status is not completed. Now you can go ahead by your self and play with Query as you wish and make it to complex. But it is a working example.

void DoIt()
{
using (ClientContext ctx = ClientContext.Current)
{

string OrderBy = <OrderBy><FieldRef Name=’Created’ Ascending=’FALSE’/></OrderBy>;
                string Where = <View><Query><Where><And> +
                        <Or> +
                            <Membership Type=’CurrentUserGroups’> +
                                <FieldRef Name=’AssignedTo’/> +
                            </Membership> +
                            <Eq> +
                                <FieldRef Name=’AssignedTo’/> +
                                <Value Type=’Integer’> +
                                    <UserID/> +
                                </Value> +
                            </Eq> +
                        </Or> +
                        <Neq> +
                            <FieldRef Name=’Status’/> +
                            <Value Type=’Text’>Completed</Value> +
                        </Neq> +
                    </And></Where></Query> + OrderBy + </View>;

CamlQuery Query = new CamlQuery();
Query.ViewXml = Where;

TasksListItemCollection = ctx.Web.Lists.GetByTitle(“Tasks”).GetItems(Query);
ctx.Load(TasksListItemCollection);

ctx.ExecuteQueryAsync(Success, Fail);

};
}

void Success(object sender, ClientRequestSucceededEventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
try
{
txtTaskCount.Text = TasksListItemCollection.Count.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString() + ex.StackTrace);
}
finally
{

}
});
}

void Fail(object sender, ClientRequestFailedEventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(“Failed to Load Items ” + e.Exception.ToString());
});
}

Thanks to Thousands of Blogers who blogged about Silverlight and SharePoint Client Object Model.