Yesterday I was working through another question in the Silverlight Forums about how to upload video to Silverlight Streaming via code. At first I tried to reference the Video.Show application, but there is a lot of code there and it doesn’t help if you just want to upload a bunch of videos to the same application. So I ended up taking some of the code from Video.Show and some of the code from the SDK/API and created a very simple Utility class to help with the process.
You can download the code on the Code Gallery site. It is very simple in that there is no error handling and I didn’t create a Silverlight version yet. I did implement GET, POST, PUT, MKCOL, and DELETE as well as creating the functionality to package a bunch of videos into a single zip which can be posted all at once.
A few examples from the code, first creating a directory and PUTting a file in it:
WebDavClient client = new WebDavClient("Your AppID", "Your Key"); // get those from http://silverlight.live.com client.CreateFolder("MyVideos"); client.PutFile("MyVideos","C:\\videos\reallyCoolVideo.wmv");
Next, packaging up a bunch of videos and POSTing the zip as an application:
WebDavClient client = new WebDavClient("Your AppID", "Your Key"); // get those from http://silverlight.live.com client.PackageAndPostFiles("MyVideos","C:\\videos\firstCoolVideo.wmv","C:\\videos\anothercoolVideo.wmv");
Let me know if you’d like to see a Silverlight version (be easy to implement) or if there are any other features you’d like added.
Enjoy!