Using the Silverlight Object Model
Recently I moved to a new project where I have to integrate Silverlight with SharePoint. I had done a few posts regarding this also. Yesterday I found that in SharePoint 2010(SharePoint foundation), Microsoft introduces Silverlight Object Model which helps to access SharePoint Lists and Document Libraries directly from Silverlight.
Here is my first experiment with Silverlight Object Model which helps to retrieve all the Lists from a given SharePoint site, and displays it in a Combo Box.
private Web oWebSite;
private ListCollection collList;
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
using (ClientContext clientContext = new ClientContext("http://sharepoint2010/"))
{
this.oWebSite = clientContext.Web;
this.collList = this.oWebSite.Lists;
clientContext.Load(collList);
clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
}
}
private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
this.Dispatcher.BeginInvoke(new Action(DisplayLists));
}
private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
MessageBox.Show("An error occured.\n" + args.Message + "\n" + args.StackTrace);
}
private void DisplayLists()
{
foreach (List item in collList)
{
lstItems.Items.Add(item.Title);
}
}
Because query execution is asynchronous when you use the SharePoint Foundation Silverlight object model, you must pass delegates for callback methods as parameters in the ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler) method.
The hash value is not correct – Silverlight Installation Error
While installing Silverlight some time you may get an error like The hash value is not correct. You can get more details about the error on clicking the Log File link in the error dialog. This error is coming may be because the setup is unable to download the Silverlight_Developer.exe / Developer runtime failed to download correctly.
You can resolve this error by copy / paste the Silverlight_Developer.exe to the “%TEMP%/Silverlight 3.0 Tools folder”. You can download the Silverlight_Developer.exe from here – http://go.microsoft.com/fwlink/?LinkID=150228
Community Tech Day – 23rd Oct 2010 – Kochi
K-MUG,one of the most successful technical community in India, is organizing Community Tech Days(CTD) in Kochi on 23rd Oct, 2010
Location : IMA House, J. N. International Stadium Road,Palarivattom P.O., Cochin 682025, Kerala
Agenda
09:15 – 09:30 Welcome and Community update by Sreejumon
09.30 – 10:15 .NET Serialization And XML by Praseed Pai
10.15 – 11:15 T-SQL Tips and Tricks with SQL Server by Vinod Kumar
Tea Break (15 min)
11.30 – 12:30 Security Auditing and Accountability under Windows 2008 by Manu Zacharia
12.30 – 01:15 NoSQL databases in .NET Apps by Shiju Varghese
Lunch Break (45 min)
02.00 – 03:00 Entity Framework 4 by Shalvin
03:00 – 04:00 TBD
04.00 – 05:00 TBD
05:00 – 05:30 Closing Ceremony
For more details visit here
Silverlight in Sharepoint (WSS 3.0)
Recently I got an assignment to integrate Silverlight to WSS 3.0, in Sharepoint Foundation(WSS 4.0) there is an out of the box web part available to do the integration. Instead of using that, in this post I am creating a reusable web part which helps to load Silverlight application in SharePoint. It is lot similar like smart part web part in WSS, which helps to render dotnet user controls (ACSX) files as webparts.
Here is my web part code. It uses two JavaScript files as includes, first one the Silverlight.js, which is used by the Silverlight runtime, other one contains the script part which handles any error. Both of this files need to copied to LAYOUTS folder so that we can re-use the code to any application in the server.
public class SilverlightWebpart : WebPart
{
private string _xapFileName = string.Empty;
private int _contentHeight = 100;
private int _contentWidth = 200;
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ClientScriptManager _ClientScriptManager = Page.ClientScript;
if (!_ClientScriptManager.IsClientScriptIncludeRegistered("sl_javascript"))
_ClientScriptManager.RegisterClientScriptInclude(this.GetType(), "sl_javascript", "/_LAYOUTS/SL3/Silverlight.js");
if (!_ClientScriptManager.IsClientScriptBlockRegistered("SilverlightError"))
{
_ClientScriptManager.RegisterClientScriptInclude(this.GetType(), "SilverlightError", "/_LAYOUTS/SL3/SilverlightError.js");
}
}
public override void RenderControl(HtmlTextWriter writer)
{
writer.WriteLine( string.Format("</pre>
<div id="\"silverlightControlHost\"" style="_0height: {0};">",
this._contentHeight.ToString(), this._contentWidth.ToString()));
writer.WriteLine("<object width="\"100%\"" height="\"100%\"" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name=""source"" value="\"{0}\"/" /><param name=""onError"" value="\"onSilverlightError\"" /><param name=""background"" value="\"white\"" /><param name=""minRuntimeVersion"" value="\"3.0.40818.0\"" /><param name=""autoUpgrade"" value="\"true\"" /><param name="src" value="\"data:application/x-silverlight-2,\"" /><embed width="\"100%\"" height="\"100%\"" type="application/x-shockwave-flash" src="\"data:application/x-silverlight-2,\"" "source"="\"{0}\"/" "onError"="\"onSilverlightError\"" "background"="\"white\"" "minRuntimeVersion"="\"3.0.40818.0\"" "autoUpgrade"="\"true\"" />"); writer.WriteLine(string.Format("", this._xapFileName)); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine(""); writer.WriteLine("<a href="\"http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0\"" style="\" text-decoration:none\"">"); writer.WriteLine("<img src="\"http://go.microsoft.com/fwlink/?LinkId=161376\"" alt="\" Get" style="\"border-style:none\"/" />"); writer.WriteLine("</a>"); writer.WriteLine("</object><iframe id="\"_sl_historyFrame\"" style="_0visibility: hidden; height: 0px; width: 0px; border: 0px\";" width="320" height="240"></iframe></div>
<pre>
");
}
[WebBrowsable(true),
WebDescription("Specify the Height of the XAP File Content"),
WebDisplayName("Content Height"),
Personalizable(PersonalizationScope.User)]
public int ContentHeight
{
get
{
return this._contentHeight;
}
set
{
this._contentHeight = value;
}
}
[WebBrowsable(true),
WebDescription("Specify the Width of the XAP File Content"),
WebDisplayName("Content Width"),
Personalizable(PersonalizationScope.User)]
public int ContentWidth
{
get
{
return this._contentWidth;
}
set
{
this._contentWidth = value;
}
}
[WebBrowsable(true),
WebDescription("Specify the XAP File to load"),
WebDisplayName("XAP File Name"),
Personalizable(PersonalizationScope.User)]
public string XAPFile
{
get
{
return this._xapFileName;
}
set
{
this._xapFileName = value;
}
}
}
The code is pretty self-explanatory. After deploying the webpart and adding the webpart to the Page, select Modify Shared Webpart, you will get Sharepoint customize option like this.
Please make sure you created a Folder with name SL3 in the _LAYOUTS folder, and copied the two javascript files to the location. The output of the Silverlight project also you need to copy to the Folder. The location will be C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\SL3. Specify the XAP File Name property as the XAP File copied to SL3 folder from ClientBin folder. You can also modify the Height and Width of the silverlight application. Click Apply and OK, exit from Edit Mode. The Silverlight application is integrated to sharepoint.
Creating a WebPart using Visual Web Developer Express
Recently I installed the WSS 3.0 in my machine. In this post I am talking about how to develop a web part using Visual Web Developer express, which can be deployed in WSS 3.0. From ASP.Net 2.0 onwards WSS Sharepoint class is inheriting from WebPart class in ASP.Net, but the Sharepoint WebPart class contains more features to create connected WebParts etc.
- Create a Class Library project in VWD Express; I am using VWD 2010, and after creating the project make sure you choose the Target framework as .Net Framework 2.0. Otherwise you may get some unable to load target assembly error from WSS.
- Add Reference of System.Web.
- Create a Class and inherit that from WebPart class, which is available in System.Web.UI.WebControls.WebParts namespace.
- Override the CreateChildControls() method, which helps to add /setup ASP.Net controls to the webpart, also you need to override the RenderControl() method, which helps to render the control to the Page.
- Build the assembly; put the DLL to the bin of your Website, most probably it will be located in C:\inetpub\wwwroot\wss\VirtualDirectories\{port}\
- Also you need to make the assembly into the SafeControl list of the web.config file of the website, which will be in C:\inetpub\wwwroot\wss\VirtualDirectories\{port}\ this location.
- Now you need to import the WebPart in WSS, you need to Select the Site Actions > Site Settings > Web Parts page. This page will display all the webparts available in the Website. You need to click on the New Link. And from the New Web Parts page, you need to select the new web part you added to the Bin folder.
- The selected webpart will be added to the Web Part Gallery.
- Now go to any page, select the Edit Page option from Site Actions. Click on the Add Web Part button, and you can see the newly added web part in the Add WebPart dialog.
public class SampleWebPart : WebPart
{
private TextBox t;
private Calendar c;
private DateTime _userDOB = DateTime.Now;
protected override void CreateChildControls()
{
this.t = new TextBox();
t.Text = this._userDOB.ToString();
this.c = new Calendar();
c.SelectionChanged += new System.EventHandler(c_SelectionChanged);
this.Controls.Add(t);
this.Controls.Add(c);
}
void c_SelectionChanged(object sender, System.EventArgs e)
{
this.t.Text = this.c.SelectedDate.ToString();
}
public override void RenderControl(HtmlTextWriter writer)
{
RenderChildren(writer);
}
[WebBrowsable(true),
WebDescription("Date of Birth of the User"),
WebDisplayName("DOB"),
Personalizable(PersonalizationScope.User)]
public DateTime UserDOB
{
get
{
return _userDOB;
}
set
{
_userDOB = value;
}
}
}
And this is the web part running on my home page.
The attributed defined in the “UserDOB” property helps to customize the web part.






