I am trying to to use the AsyncUpload so that when a user chooses a file to upload via ajax it is sent to the server and put into a collection object with existing attachments associated with my form. Using a sample from the demos and documentation I have it doing, this, but I have an issue that when it uploads I want to clear the pending upload screen. Essentially I want to clear the UploadedFiles items when it does the ajax routine. However no matter what I do it won't work. I get an enumeration error when I use the clear method. Any help on this would be appreciated. Again all I want is when the upload file is selected an ajax call posts it back, it's added to a collection and then upload control is cleared so they can add more.
ASP.NET
<
telerik:RadAsyncUpload
ID
=
"rulAttachments"
runat
=
"server"
RenderMode
=
"Lightweight"
AutoAddFileInputs
=
"false"
Localization-Select
=
""
MaxFileSize
=
"5000000"
OnClientFilesUploaded
=
"OnClientFilesUploaded"
OnFileUploaded
=
"rulAttachments_FileUploaded"
></
telerik:RadAsyncUpload
>
Javascript
function
OnClientClickingUpload(sender) {
//sender.set_autoPostBack(false);
$telerik.$(
".ruFileInput"
).click();
}
(
function
(global, undefined) {
var
demo = {};
function
OnClientFilesUploaded(sender, args) {
$find(demo.ajaxManagerID).ajaxRequest();
}
function
serverID(name, id) {
demo[name] = id;
}
global.serverID = serverID;
global.OnClientFilesUploaded = OnClientFilesUploaded;
})(window);
//<![CDATA[
serverID(
"ajaxManagerID"
,
"<%= RadAjaxManager.GetCurrent(Page).ClientID %>"
);
//]]>
C#
protected
void
rulAttachments_FileUploaded(
object
sender, FileUploadedEventArgs e)
{
if
(rulAttachments.UploadedFiles.Count > 0)
{
byte
[] content;
using
(Stream str = e.File.InputStream)
{
content =
new
byte
[str.Length];
str.Read(content, 0, content.Length);
}
SelectedInventoryRequest.Attachments.Add(
new
BLL.FileAttachment { Id =
""
, Description = e.File.FileName, FileData = content, NewFile =
true
, FilePath = ConfigurationManager.AppSettings[
"DocumentumInProcessPath"
+ ConfigurationManager.AppSettings[
"CurrentRegion"
]] +
"/"
+ SelectedInventoryRequest.InventoryRequestID.ToString() });
rulAttachments.UploadedFiles.RemoveAt(0);
BindAttachments();
}
}