{"id":1883,"date":"2009-10-18T16:19:38","date_gmt":"2009-10-18T15:19:38","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/1883-silverlight-data-image-upload-example-code.html"},"modified":"2009-10-18T16:19:38","modified_gmt":"2009-10-18T15:19:38","slug":"silverlight-data-image-upload-example-code","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/1883-silverlight-data-image-upload-example-code.html","title":{"rendered":"Silverlight data, image upload example code"},"content":{"rendered":"<p>Some time ago I created a simple example of CRUD (Create, Retrieve, Update, Delete) in Silverlight with ASP.NET \u2013 you can view it online <a href=\"http:\/\/www.itwriting.com\/silverlightdata\" target=\"_blank\">here<\/a>. I originally posted it in April; see <a href=\"http:\/\/www.itwriting.com\/blog\/1374-a-silverlight-database-application-with-image-upload.html\" target=\"_blank\">this post<\/a> for details. Several people asked me for the code and I\u2019ve not done so until now \u2013 mainly because of the hassle involved in making a Visual Studio solution portable as a demo. The Silverlight app was originally written in Visual Basic and I\u2019ve now ported it to C# for convenience. The version on this site runs on Mono, but the demo code is for Visual Studio 2008 on Windows \u2013 there really is no difference apart from the database code.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.itwriting.com\/images\/sldata-new.gif\" \/><\/p>\n<p>One issue I had with the demo was providing a database. I wanted something easier than just providing the SQL to create a database, ideally a solution that would just open and run immediately. I tried using SQL Server Compact Edition but Microsoft has actually hard-coded something that stops you using this for an ASP.NET application and I got an exception accordingly. I\u2019ve therefore used Access. I wouldn\u2019t consider this for a real web app, but it is convenient for a demo.<\/p>\n<p>The code is somewhat retro \u2013 no entity framework, no WCF, no LINQ &#8211; except an expression to filter the datagrid \u2013 and old-style ASP.NET Forms Authentication. It would be good to convert it to use <a href=\"http:\/\/code.msdn.microsoft.com\/RiaServices\" target=\"_blank\">RIA Services<\/a>, which I may do if I can find the time. This may mean the code is no use to you at the moment.<\/p>\n<p>Although it is a simple app and not production-ready, I found it interesting to do. Silverlight code is easy to write, but interacting with remote web services for all the content is more challenging. There are flaws \u2013 for example, I\u2019ve not handled what happens when multiple users edit the data simultaneously.<\/p>\n<p>There are a few little hacks too. For example, I have an edit form where you can upload an image. I want to have the image display as soon as it is uploaded, but found that if I try to display it in the WebClient\u2019s OpenWriteCompleted event handler it fails; somehow the file is not quite ready to be served. I use a timer to insert a small delay.<\/p>\n<p>Another issue was <a href=\"http:\/\/www.itwriting.com\/blog\/1381-faking-synchronous-web-service-calls-in-silverlight.html\" target=\"_blank\">faking synchronous web service calls<\/a>.<\/p>\n<p>Anyway, I\u2019ve now uploaded the code and you can find it <a href=\"http:\/\/www.itwriting.com\/silverlightdata.zip\" target=\"_blank\">here<\/a>. If there is enough interest I\u2019ll put it in a repository to make it easier to add bug-fixes and so on.<\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:911b7455-af9f-4fb7-b1d4-85a98df78865\" class=\"wlWriterEditableSmartContent\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/silverlight\" rel=\"tag\">silverlight<\/a>,<a href=\"http:\/\/technorati.com\/tags\/web+development\" rel=\"tag\">web development<\/a>,<a href=\"http:\/\/technorati.com\/tags\/ria\" rel=\"tag\">ria<\/a>,<a href=\"http:\/\/technorati.com\/tags\/asp.net\" rel=\"tag\">asp.net<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Some time ago I created a simple example of CRUD (Create, Retrieve, Update, Delete) in Silverlight with ASP.NET \u2013 you can view it online here. I originally posted it in April; see this post for details. Several people asked me for the code and I\u2019ve not done so until now \u2013 mainly because of the &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/1883-silverlight-data-image-upload-example-code.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Silverlight data, image upload example code<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,77,80,94,96],"tags":[],"class_list":["post-1883","post","type-post","status-publish","format-standard","hentry","category-net","category-silverlight","category-software-development","category-visual-studio","category-web-authoring"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=1883"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1883\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=1883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=1883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=1883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}