Silverlight ASP.NET control: ClientServices

Posted at Sat, 05 May 2007 16:30:46 GMT by Wilco Bauwer

Client-side scripting comes with a bunch of limitations. There's no client storage you can read from or write to. You can't read from files a user selected from your <input type='file' /> element, etc. To address this, I've encapsulated a few services that Silverlight enables. I have packaged this up as an ASP.NET control, but nothing prevents you from directly using the Silverlight assembly and host it on an arbitrary webserver.

For the results of this control, check out the ClientServices demo. Or download the control's source-code.

JavaScript:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 

function saveDraft() {
    /* Get the scriptable, managed services object */
    var services = $get("clientServices").Content.services;
    var messageTextBox = $get("messageTextBox");

    /* Save the contents of the textbox in a file called Draft.txt on the 
       client, using isolated storage. We can read from this using 
       services.ReadFile("Draft.txt"), even if the user restarted the browser. */
    services.SaveFile("Draft.txt", messageTextBox.value);
}

I can't make the live demo of this work on IE7.
But i am really impressed and would really need this (draft save)!

Let me know (by email) if it is still supposed to work!

Thanks
Your message will be encoded/formatted when it is displayed. If you want to post code, please put the code inside [code=X][/code] tags, where X is the language of your code (C#, ASPX, SQL, etc).
Name:
Email:
(will be encoded using JavaScript to keep it functional and prevent it from being picked up by spammers)
Url:
 
Message:
3 + 3 =