Couple of Issues

Nov 18, 2008 at 5:14 AM
Very nice application.
I have two issues I'd need to resolve to use this. One is the ability to have other variables for each file to be uploaded. For example, a text input box for a user-friendly name for the file and a text input box for a description of the file. These two items, along with the file name, would then be added to a database when the uplaod is submitted.

Also, it would be nice to have the option of also adding the file to SQL database rather than to a server directory.

Any chance you could provide some pointers on hos to accomplish this?
Nov 18, 2008 at 8:38 PM
Edited Nov 18, 2008 at 8:39 PM
Well, there are a couple of options for the first item.  You can use an html textbox to enter the user-friendly name and then read it from silverlight and append the name to the upload page or do a postback and append it to the upload page in the code behind of your page.  Or modify/add silverlight code to include a textbox.  This is option I would choose.  I would create a new silverlight project and just add the upload control to the project.  Then you can add a textbox and append the name to the upload page property of the upload control.  It would be passed as a query parameter.

Then in the upload httphandler you can get the name from the query using ctx.Request.QueryString["friendlyName"].  I would do this in the FileUploadCompleteEvent of the FileUploadProcess object.  See the FileUpload.cs file for an example in the source code.  Then you can save the file to the database and then delete the temporary one created when uploading.

To add the file to the database, get the bytes of the file and add them how you normally would.  To get the bytes:



[] bytes = File.ReadAllBytes(args.FilePath);

There are examples of adding files to databases, just do a search.  It would depend on the database.  If using SQL Server, you can use linq to sql and make it extremely easy.  Just make sure to delete the file after inserting it, otherwise you will have a copy on the file system as well.

Let me know if you need any further explanations,





Dec 8, 2008 at 8:15 PM
Hello Darick,

When i tried the SilverlightFileUploadWeb code, i got this error: Unhandled Error in Silverlight 2 Application.  Code: 2014.  Category: InitializedError.
Could you show me how to fix this error and got this project running?

Thanks a lot,