Thursday, May 7, 2009

Integrate Silverlight in SharePoint

1) Initially we require html Page,Images and .XAP file of the Silverlight Application.

2) Upload the .xap file and Images Required into the SharePoint document library.

3) Add the Content Editor WebPart in the Page .

4) Copy the Script tag consists of javascript and html tags present in the body tag from the html page and Paste it in the Source Editor of the Content Editor WebPart, looks like as shown below

<script type="text/javascript">
function onSilverlightError(sender, args) {

var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;

var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n" ;
errMsg += "Code: "+ iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError")
{
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError")
{
if (args.lineNumber != 0)
{
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
<!-- Runtime errors from Silverlight will be displayed here.
This will contain debugging information and should be removed or hidden when debugging is completed -->
<div id='errorLocation' style="font-size: small;color: Gray;"></div>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="810px" height="550px">
<param name="source" value="/Shared Documents/Trial.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="initParams" value="ServiceUrl=http://ws27/Trial.Service/Service1.svc/" />
<param name="autoUpgrade" value="true" />
<a href="
http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
<img src="
http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object> </div>

5) Provide the actual Path of the xap file in param tag shown above.

1 comment:

digital signature Adobe Acrobat said...

Thanks for a great read. As Steve Jobs said : “Innovation is what separates leaders from followers.”