Hi,
I am working on a Silverlight application to upload documents to a SharePoint site with a custom upload handler in the backend. My issue is: I can’t capture the upload progress for all uploaded files. The “ProgressChanged” event fires for the last uploaded file only. Can yopu please review the code below and let me know if I am missing anything?
I am using Silverlight 4 with Telerik Controls for Silverlight version 2010.2.812.1040
Following is a snippet of the Silverlight code
<
RadInput:RadUpload
Style
=
"{StaticResource UploadStyle}"
x:Name
=
"Upload"
Visibility
=
"Collapsed"
Filter
=
"Documents (*.doc;*.xls;*.ppt;*.pdf)|*.doc;*.xls;*.ppt;*.pdf;*.docx;*.xlsx;*.pptx|All Files(*.*)|*.*"
FilterIndex
=
"0"
IsAutomaticUpload
=
"True"
OverwriteExistingFiles
=
"True"
TargetFolder
=
""
IsAppendFilesEnabled
=
"True"
FileUploadStarting
=
"Upload_FileUploadStarting"
FileUploaded
=
"Upload_FileUploaded"
ProgressChanged
=
"Upload_ProgressChanged"
UploadStarted
=
"Upload_Started"
BufferSize
=
"1024000"
MaxFileSize
=
"51000000"
MaxUploadSize
=
"1010000000"
FileUploadFailed
=
"Upload_FileUploadFailed"
IsMultiselect
=
"False"
/>
void
Upload_ProgressChanged(
object
sender, EventArgs e)
{
Action<
string
,
int
> d =
(name, percent) =>
{
//do something
};
var radUpload = sender
as
RadUpload;
if
(radUpload !=
null
)
{
if
(Dispatcher.CheckAccess())
{
d(radUpload.CurrentSession.CurrentFile.Name,
Convert.ToInt32(radUpload.CurrentSession.CurrentFileProgress));
}
else
{
Dispatcher.BeginInvoke(d, radUpload.CurrentSession.CurrentFile.Name,
Convert.ToInt32(radUpload.CurrentSession.CurrentFileProgress));
}
}
}
Also here is the code for the upload handler
public
class
UploadHandler
: RadUploadHandler
{
private
const
string
paramNameSessonId =
"sessionId"
;
private
const
string
paramNameFilePath =
"filePath"
;
private
const
string
paramNameSessonType =
"sessionType"
;
private
string
fileServerUrl =
string
.Empty;
public
override
bool
SaveChunkData(
string
filePath,
long
position,
byte
[] buffer,
int
contentLengtgh,
out
int
savedBytes)
{
if
(!
base
.SaveChunkData(filePath, position, buffer, contentLengtgh,
out
savedBytes))
{
return
false
;
}
if
(IsFinalFileRequest())
{
try
{
using
(FileStream stream = File.OpenRead(filePath))
{
byte
[] fullBuffer =
new
byte
[stream.Length];
stream.Read(fullBuffer, 0, (
int
)stream.Length);
var name = GetFileName();
Core.Facade.DocLibraryFacade.AppendToFile(
name,
Request.Form[paramNameSessonId],
Request.Form[paramNameSessonType],
fullBuffer, 0,
out
fileServerUrl);
}
}
catch
(Exception exception)
{
savedBytes = 0;
this
.AddReturnParam(RadUploadConstants.ParamNameMessage,
string
.Format(
"Cannot save the document reason why {0}"
, exception));
return
false
;
}
}
return
true
;
}
public
override
string
GetFilePath(
string
fileName)
{
return
base
.GetFilePath(fileName) + Request.Form[paramNameSessonId];
}
public
override
string
TargetFolder
{
get
{
return
BoozConfig.Current.UploadHandler.TempFolderRelativePath;
}
set
{
}
}
public
override
string
TargetPhysicalFolder
{
get
{
return
BoozConfig.Current.UploadHandler.TempFolderPhysicalPath;
}
set
{
}
}
public
override
Dictionary<
string
,
object
> GetAssociatedData()
{
return
new
Dictionary<
string
,
object
> {{paramNameFilePath, fileServerUrl}};
}
}
Thanks
Qusai