I tried searching for a simple file upload control for silverlight 4 and came across some excellent multi-file upload controls specially the one from codeplex "http://silverlightfileupld.codeplex.com/ ", but that is not what I needed due to complexity or the difficulty of code editing or changing to adjust according to my project .So I began in my personal file uploader as the following,
1 - Open file dialogue to get the file
public OpenFileDialog fileDialog = null; fileDialog.Multiselect = false; // one file at a timefileDialog.Filter = ""; // Add file filter
|
2 - WCF web service to write the file to the server with the following function
[OperationContract]
public void SaveFile(UploadFile UploadFile) { FileStream FileStream = new FileStream("[WhateverPathWithPermission]" + UploadFile.FileName, FileMode.Append);
FileStream.Write(UploadFile.File, 0, UploadFile.File.Length); FileStream.Close(); FileStream.Dispose(); }
|
3 - Add to WCF service a class contract to handle segment blocks transfer between client and server.
[DataContract]
public class UploadFile { [DataMember] public string FileName;
[DataMember] public byte[] File; }
|
4 - Handle file blocks server transfer.
Join the conversation! Your thoughts help the community grow.