190 likes | 357 Views
Silverlight in SharePoint WebParts. You got peanut butter in my chocolate. Who Am I?. Shawn Wildermuth shawn@agilitrain.com C# MVP, MCSD, MCT, INETA Speaker, Author AgiliTrain Silverlight for SharePoint – Atlanta, June 2-4, 2009 Silverlight Tour – Atlanta, July 20-22, 2009
E N D
Silverlight in SharePoint WebParts You got peanut butter in my chocolate
Who Am I? • Shawn Wildermuth • shawn@agilitrain.com • C# MVP, MCSD, MCT, INETA Speaker, Author • AgiliTrain • Silverlight for SharePoint – Atlanta, June 2-4, 2009 • Silverlight Tour – Atlanta, July 20-22, 2009 • Advanced Silverlight – Atlanta, August 3-4, 2009
Agenda • Why Silverlight? • SharePoint Integration • Linking Projects • Hosting in SharePoint • Using Web Services • Debugging
What’s SharePoint? • I am not a SharePoint Expert… • …Some of the Techniques Here May Be Hacky… • Goal is to show how it *can* work • So you can apply it to your exceptional SharePoint Skills
Why Silverlight in SharePoint • Leave to SharePoint (and Web) What They Do Well • Silverlight for Islands of Content • Where Graphics and Interactivity Helps • Don’t Overuse it
Using Silverlight in WebPartProject • Can Create Silverlight in Same Solution • No Official Linking • Must Do Manually • Post-Build, Shared File, MSBuild • Add XAP to WebPart XML file for Deployment
Using Silverlight in WebPartProject • WebPart.xml • May be better as separate module <?xml version="1.0" encoding="utf-8"?> <Elements Id="..." xmlns="..." > <Module Name="WebParts" List="113" Url="_catalogs/wp"> <File Path="SilverlightTaskViewer.webpart" Url="SilverlightTaskViewer.webpart" Type="GhostableInLibrary" /> <File Path="SilverlightTasksWidget.xap" Url="SilverlightTasksWidget.xap" Type="GhostableInLibrary" /> </Module> </Elements>
Demo New Silverlight Web Part
Hosting in SharePoint • WebPart Can Create HTML Code • LiteralControl and ObjectTag public class SilverlightTaskViewer : WebPart{ protected override void CreateChildControls() { base.CreateChildControls(); string hostTag = @"<object ...></object>"; // Put the Object Tag the control collection LiteralControlslObj = new LiteralControl(hostTag); Controls.Add(slObj); } }
Hosting in SharePoint (2) • Browser Cache a Problem • SPUtility.MakeBrowserCacheSafeLayoutsUrl() • Can help but must be in a template to work
Hosting in SharePoint (3) • WebPart Can Create HTML Code • Can Use Silverlight control and ScriptManager • But why?
Demo Showing Silverlight in WebPart
Using SharePoint Web Services • Creating ServiceReferences to SP “Just Works” • http://<Machine>/_vti_bin/Lists.asmx • http://<Machine>/_vti_bin/Alerts.asmx • Etc.
Using SharePoint Web Services (2) • Data Returned is Typically XML • Must Use Projection to Shape for DataBinding XElement tasks = e.Results; varqry = from i in e.Result.Descendants(rowName) select new Task() { Title = i.Attribute("ows_Title").Value, Priority = i.Attribute("ows_Priority").Value, Status = i.Attribute("ows_Status").Value, }; theList.ItemsSource = qry.ToList();
Demo Consume a Web Service
Debug Considerations • Pain Points with Debugging the Silverlight Code • Browser Cache Need Invalidated to Debug • “Run with Debugging” Only Works Locally • Remote Debugging Silverlight is not trivial • Attach To Process Works Well • Cross Domain May Be An Issue Too.
Demo Debugging Silverlight in WebPart
Questions? • Links: • My Blog (Code is Available Here) • http://wildermuth.com • My Email: • shawn@agilitrain.com • Silverlight.NET • http://silverlight.net Shawn Wildermuth AgiliTrain Microsoft MVP (C#), MCSD