How To Upload File In Silverlight Sample

In My Article File Handling in Silverlight I have discussed that we can use file upload using the Isolated storage of Silverlight. We also have another way using the classic (.asmx) Web services or WCF.
  1. How To Upload File In Silverlight Samples

You can upload files from client PCs to the server using Silverlight. If you want to display the thumbnail of the first page, then you will need to open this using a third party control. Silverlight has no native support for manipulating PDF files.

Here I am discussing about the classic .asmx web services to upload files in the Silverlight applications.

Steps :

1. Create a Silverlight project in Visual Studio 2008 or beyond. As Silverlight 3.0 is released so you can use that or go with Silverlight 2.0 hardly matters.
2. Make these important changes in the properties of FileUploadASMX.Web project
a. Right click on FileUploadASMX.Web.
b. Select Properties
c. Under Web tab Select Specific port and give the port number I am using port number 1366 Note: we are using specific port so that every time we need not to run the web service to use it and it won't change its address. If you don't want to use specific port then either host your web service on IIS or run the web service every time and update the service reference each time before running the application.
d. Save The Properties Page and close it.
3. Add a new Web service to the FileUploadASMX.Web project and name it as uploadService.asmx
4. Include the name space System.IO
5. Create a new web method
6. Save the Service Leaving other settings as it is. or you want then you can delete the Helloworld example web method.
7. Coming back to the FileUploadASMX project.
8. Create A class FilesClass
9. Create Two Buttons in the Mainpage.xaml.
a. To Choose File
b. To upload File At the specified folder in the Web Service
The Code Will look like
10. Add the service reference to the Silverlight project name it uploadService

How To Upload File In Silverlight Samples

11. Navigating to the event for choose buttonFile
12. Now Lets code for the upload event Navigate to the event
The Code Is Attached you can Download the files and enjoy file handling
Thanks and Regards
Meetu Choudhary
My Blog My Web My Forums