Q:

SharePoint 2010/Silverlight: Pass custom parameters programmatically

I need to pass the current logged in user's information to a Silverlight application through SharePoint 2010 Silverlight webpart. I am familiar with the custom "initialization parameters" in the Silverlight web parts properties but that does not solve my problem because of the nature of the information. The "Initialization Parameters" is fixed information and logged-in user information changes. I need to pass parameters programmatically to the silverlight application.
Maybe someone could point to a custom implementation of Silverlight host webpart. Any help would be much appreciated.
Thanks.

A:

To pass parameters dynamically to a Silverlight application, add a visual web part to your SharePoint 2010 project. and add the following code to the markup.
<asp:Panel ID="SilverlightPanel" runat="server" >
    <div id="silverlightControlHost" style="width:100%;height:150">
        <object id="SLServicesBanner"
                data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="500" height="300">
            <param name="source" value="your_xap_file_goes_here"/>
            <param name="initParams" value="<%= InitParameters %>" />
            <param name="background" value="white" />
            <param name="minRuntimeVersion" value="4.0.50401.0" />
            <param name="autoUpgrade" value="true" />
            <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
                <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
            </a>
        </object>
        <iframe id="_sl_historyFrame" style="visibility:hidden; height:0px; width:0px; border:0px"> 
        </iframe>
    </div>
</asp:Panel>

Observer the "initParams" attribute. You can set it up to anything from codebehind.
Thanks

