| Dart Home | PowerWEB File Upload for ASP.NET | Custom Development | Reply | PowerWEB File Upload for ASP.NET Topics | Forums |
| Author | Forum: PowerWEB File Upload for ASP.NET Topic: HOW TO: Get filename(s) on the client before an upload is processed |
John Talarico![]() From: Rome, NY USA Posts: 630 Member Since: 06/01/05 |
posted April 15, 2008 11:31 AM Several customers have asked a few (seemingly) simple questions surrounding the selection of files on the client: Q: Can I have the website choose the files to upload instead of requiring users to pick the files? A: The underlying technologies behind an HTTP upload come with some restrictions. They do not allow a website or automated script to initiate an upload without human intervention. This is a security restriction and protects us from nefarious developers that would build sites that upload common files without us knowing it. So, the only way to initiate file selection is through a dialog, and even that must be triggered by a human action. Q: How do you get the file name or names before an upload begins? And, how do you provide a quick confirmation dialog such as "Are you sure you want to upload <filename>"? A: I've provided a little script that demonstrates how to override the PowerWEB File Upload function (pwOnDialogSelect) that is called whenever files are selected in the dialog. If this script is placed at the bottom of your web form, it will give you the opportunity execute your own custom code or issue a confirmation dialog before uploading. <script> var pwOnDialogSelect_old = pwOnDialogSelect; pwOnDialogSelect = function(uploadID, selectedFilename) { var conf = confirm("Are you sure you want to upload " + selectedFilename + "?"); if (conf) pwOnDialogSelect_old(uploadID, selectedFilename); } </script> Code explained: 1) var pwOnDialogSelect_old = pwOnDialogSelect; This reassigns the existing function to a new handle so we can manually call it later. The function takes two parameters, but we only need to re-point the function name. 2) pwOnDialogSelect = function(uploadID, selectedFilename) Here is wehere we redefine the guts of the function, but copy the interface so existing code still works. 3) var conf = confirm("Are you sure you want to upload " + selectedFilename + "?"); This displays a standard JavaScript confirmation dialog with the text constructed from the list of file(s) passed into the function. If the user clicks OK, conf will be true, otherwise false. 4) if (conf) pwOnDialogSelect_old(uploadID, selectedFilename); If conf is true, we execute the old function, passing along the argument list. This override technique is also called function or event chaining in JavaScript. |
| ewwilson From: test, AL USA Posts: 3 Member Since: 07/30/09 |
posted July 30, 2009 3:59 PM Is there a way to get the filename list in an array for instead of a comma separated string? The reason I need this is for file name validation and since commas are valid filename characters I cannot reliably split the filename list on commas. |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted August 3, 2009 10:08 AM Hi, Unfortunately, no. The selectedFilename parameter simply returns the filename list exactly as provided by the Flash dialog. Sorry, -ken |
| Reply | PowerWEB File Upload for ASP.NET Topics | Forums |
This site is powered by
PowerTCP WebServer for ActiveX
|