locked
SilverLight to SharePoint Webpart communications RRS feed

  • Question

  • Hi everyone,

    I'm new in SilverLight world.
    I'd like to develop a SharePoint WebPart that host a SilverLight 3 application. This application is a RSS Reader. But, I would like a panel in my SilverLight application were user can specify the url of the field without opening the tool panel of the webpart. I'd like this properties of the WebPart will be saved in the WebPartStorage.Personal.
    So on a webpart side it doesn't give a lots of problem.
    But I don't know how I can do to have SilverLight talking to my WebPart.
    Somes says me that I must use a WebService. I think this is a pretty good idea. But I really don't have any idea of how my SilverLight application will identify the webpart in which it is running. And even more how SilverLight will found in which Storage it must write.
    So I need some help to understand how the WebPartStorage is working, how to write in it, and how identify a particular WebPartStorage based on a WebPart.

    Thanks a lot.
    Monday, November 9, 2009 1:33 PM

Answers

  • Sounds like a reasonable proposition. You'll need to ctreate a webservice that uses the SPLimitedWebPartManager to get a reference to your webpart. Since you're only passing one parameter to SilverLIght it's probably easiest to do it using InitParams in your Render method.


    Ch. - My Blog
    Monday, November 9, 2009 2:35 PM

All replies

  • It depends on how much data you want to transfer and how often. If it's a one time initialization when teh page loads your silverlight control, the easiest way to do it is to have your webpart render a hidden field then pass teh name of the hidden field to your silverlight control in initparams. Silverlight will be able to find teh hidden field using HTMLBridge and extract the data from it.

    To send data back from silverlight you just have silverlight populate the hidden field and pick it up in your webpart code on postback.


    If you're looking for ongoing communication between the two (I can't think of any reason whay you would though!), webservices are probably teh way to go. Although by doing that you'll have decoupled your silverlight control from yoru webpart.

    D'y want me to post some sample code for the first approach?


    Ch. - My Blog
    Monday, November 9, 2009 2:16 PM
  • Thanks for your answer.

    What I need to do is to create a RSS Reader SilverLight application. This will be contained in a webpart.
    The url of the feeds will be saved in the WebPart Storage. Each user can change the url of the field so it is saved in the Personal aera. But what my client wants is the user will be able to change the url in a panel in SilverLight without passing the page and the webpart in editing mode.
    So I think the best way is that the SilverLight get the identifier of the webpart at first init. Then the user change the rss feeds url in SilverLight. It then connect to the webservice, give the new url to it and the id of the webpart. Then the web service made the change in the WebPartStorage and the next time the webpart is loaded it have the new parameters.
    What do you think about this scenario?

    Monday, November 9, 2009 2:27 PM
  • Sounds like a reasonable proposition. You'll need to ctreate a webservice that uses the SPLimitedWebPartManager to get a reference to your webpart. Since you're only passing one parameter to SilverLIght it's probably easiest to do it using InitParams in your Render method.


    Ch. - My Blog
    Monday, November 9, 2009 2:35 PM