Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Ajax Uploader
»
Re: Validating and providing feedback
Validating and providing feedback
Last post 11-23-2009, 3:10 PM by
scpeterson
. 3 replies.
Sort Posts:
Oldest to newest
Newest to oldest
Previous
Next
11-10-2009, 12:40 PM
57035
scpeterson
Joined on 11-10-2009
Posts 3
Validating and providing feedback
Reply
Quote
Hello:
I am using the FileValidating event to check for duplicate files. If I find a duplicate file, I execute an args.Delete() to remove the file so that the FileUploaded event does not fire for that file. I want to record the names of each file that is a duplicate and present that list to my users. I've tried adding the names to a label, but the label gets cleared out each time I go back to the FileValidating event. I tried adding the information to a Session variable but that did not seem to work either. I tried populating a label in the UploadCompleted event, but if all my files are duplicates, that event will never fire.
Any ideas on how to do this would be most welcome.
11-16-2009, 9:45 PM
57196
in reply to
57035
cutechat
Joined on 07-22-2004
Posts 2,332
Re: Validating and providing feedback
Reply
Quote
Hi,
You have two solution :
1 , throw an exception in the event handler, and uploader will show the exception message.
2 , try this way :
<%@ Page Language="C#" %> <%@ Import Namespace="CuteWebUI" %> <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void UploadAttachments1_FileValidating(object sender, UploaderEventArgs args) { //you can send some data or message to client side UploadAttachments1.SetValidationServerData("File validated at " + DateTime.Now.ToString("HH:mm:ss")); //updating the UI has no effect! labelMsg.Text = "Validated!"; } protected void UploadAttachments1_FileUploaded(object sender, UploaderEventArgs args) { } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" InsertText="Add files" OnFileValidating="UploadAttachments1_FileValidating" OnFileUploaded="UploadAttachments1_FileUploaded"> </CuteWebUI:UploadAttachments> <br /> <asp:Label runat="server" ID="labelMsg" /> </div> </form> </body> <script type="text/javascript"> function CuteWebUI_AjaxUploader_OnTaskComplete(file) { //You can get the custom data here , (or using uploader.getitems()[i].ServerData) alert(file.ServerData); } </script> </html>
Regards,
Terry
11-23-2009, 3:09 PM
57353
in reply to
57196
scpeterson
Joined on 11-10-2009
Posts 3
Re: Validating and providing feedback
Reply
Quote
I tried method 2 and it seems to work just fine. In the FileValidating event, I used a string that tells the user that the file already exists and so the file will not be uploaded. I then call args.delete() to remove that file so it is not copied. Since my uploaded files may or may not be duplicates, I need to test for a message in the alert and only display an alert if there is a message, i.e., the duplicate message I added in the FileValidating event:
If
System.IO.File.Exists(fullFileName)
Then
'The file already exists on the server so we need to delete it from the temporary
' upload directory (so it doens't get called in the FileUploaded event) and alert the user
UploadAttachments1.SetValidationServerData(
String
.Format(
"A file named {0} already exists and will not be uploaded."
, args.FileName))
args.Delete()
End
If
11-23-2009, 3:10 PM
57354
in reply to
57353
scpeterson
Joined on 11-10-2009
Posts 3
Re: Validating and providing feedback
Reply
Quote
I also modified the JS script as follows:
function
CuteWebUI_AjaxUploader_OnTaskComplete(file) {
//You can set the custom data here, or use uploader.getitems()[i].ServerData)
if
(file.ServerData !=
null
&& file.ServerData !=
''
)
alert(file.ServerData);
}