Hi to all; I have an application which uses the radupload control to upload files into a SQL Database and we have found in certain situations after clicking the button upload the radupload fails to upload and instead of showing cancel pause buttons, it shows cancel and browse.
After doing some testing we have found that pdf and word files are the one causing the issue.
The following is the xaml for the RadUpload file
This the C# for all 4 events :
This is the ashx C# code:
One last thing even the radupload control is configured with SingleFilePerPostRequest = "True" in the ashx the following conditions always is false this.IsFinalFileRequest()
After doing some testing we have found that pdf and word files are the one causing the issue.
The following is the xaml for the RadUpload file
<
telerik:RadUpload
x:Name
=
"ruAttachment"
Grid.Row
=
"0"
Margin
=
"10"
Width
=
"320"
MinWidth
=
"320"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Stretch"
IsAutomaticUpload
=
"False"
UploadServiceUrl
=
"../AttachmentsPOUploadHandler.ashx"
IsEnabled
=
"{Binding Content.CanUploadAttachment, Source={StaticResource ViewModelProxy}}"
IsAppendFilesEnabled
=
"False"
OverwriteExistingFiles
=
"True"
SingleFilePerPostRequest
=
"True"
IsMultiselect
=
"False"
FilesSelected
=
"RuAttachmentFilesSelected"
FileUploadStarting
=
"RuAttachmentFileUploadStarting"
FileUploaded
=
"RuAttachmentFileUploaded"
FileUploadFailed
=
"RuAttachment_OnFileUploadFailed"
ItemContainerStyle
=
"{StaticResource OWRadUploadItemStyle}"
Visibility
=
"{Binding Content.CanExecuteEdit, Source={StaticResource ViewModelProxy},Converter={StaticResource BooleanToVisibilityValueConverter}}"
/>
This the C# for all 4 events :
private
void
RuAttachmentFileUploadStarting(
object
sender, FileUploadStartingEventArgs e)
{
e.FileParameters.Add(
"OrderId"
, ViewModel.SelectedOrder.Id);
e.FileParameters.Add(
"UserId"
, ClaimsIdentitySessionManager.Current.User.Identity.Name);
e.FileParameters.Add(
"FileName"
, ViewModel.SelectedFile.Name);
e.FileParameters.Add(
"Extension"
, ViewModel.SelectedFile.Extension);
if
(ViewModel.SelectedDocumentType ==
null
|| ViewModel.SelectedDocumentType.Id == 0)
{
}
else
e.FileParameters.Add(
"DocTypeId"
, ViewModel.SelectedDocumentType.Id);
}
private
void
RuAttachmentFileUploaded(
object
sender, FileUploadedEventArgs e)
{
ViewModel.LoadAttachments();
if
(OrderSubmitted !=
null
)
// Refresh the attachments grid
OrderSubmitted(
this
,
null
);
}
private
void
RuAttachmentFilesSelected(
object
sender, FilesSelectedEventArgs e)
{
var uploadControl = sender
as
RadUpload;
// Remove and add validate event handler
uploadControl.RemoveHandler(RadUploadItem.ValidateEvent,
new
UploadValidateEventHandler(OnValidateAttchment));
uploadControl.AddHandler(RadUploadItem.ValidateEvent,
new
UploadValidateEventHandler(OnValidateAttchment),
false
);
ViewModel.SelectedFile = e.SelectedFiles[0].File;
Thread.Sleep(2000);
}
private
void
RuAttachment_OnFileUploadFailed(
object
sender, FileUploadFailedEventArgs e)
{
}
This is the ashx C# code:
public
class
AttachmentsPOUploadHandler : RadUploadHandler
{
#region Fields
#endregion
#region Properties
#endregion
#region Methods
public
override
bool
SaveChunkData(
string
filePath,
long
position,
byte
[] buffer,
int
contentLength,
out
int
savedBytes)
{
bool
result =
false
;
savedBytes = 0;
if
(
this
.IsFinalFileRequest())
{
OWEntities context =
new
OWEntities();
int
orderId = 0;
if
(
int
.TryParse(
this
.GetQueryParameter(
"OrderId"
),
out
orderId))
{
//get order from database
POHeader order = context.POHeaders.FirstOrDefault(o => o.Id == orderId);
//get the document extention detail based on file extension from database
string
extension =
this
.GetQueryParameter(
"Extension"
).Trim(
'.'
).ToUpper();
DocumentExtension docExtension = context.DocumentExtensions.FirstOrDefault(d => d.ExtType.Trim().ToUpper().Equals(extension));
//create attachment
if
(docExtension !=
null
)
{
POAttachment attachment =
new
POAttachment()
{
CreatedById =
this
.GetQueryParameter(
"UserId"
),
CreatedDate = DateTime.Now,
DocExt = extension,
DocExtId = docExtension.Id,
DocName =
this
.GetQueryParameter(
"FileName"
),
DocSize = contentLength,
DocTypeId = Convert.ToInt16(
this
.GetQueryParameter(
"DocTypeId"
)),
POFile =
new
POFile()
{
CreatedById =
this
.GetQueryParameter(
"UserId"
),
CreatedDate = DateTime.Now,
Document = buffer,
POHeaderId = orderId
},
POHeaderId = orderId
};
context.POAttachments.AddObject(attachment);
context.SaveChanges();
}
result =
true
;
}
}
return
result;
}
#endregion
}
One last thing even the radupload control is configured with SingleFilePerPostRequest = "True" in the ashx the following conditions always is false this.IsFinalFileRequest()