How to validate a file being uploaded across a SQL db?

Last post 04-18-2013, 4:04 AM by faxxx. 11 replies.
Sort Posts: Previous Next
  •  12-14-2012, 8:57 AM 75461

    How to validate a file being uploaded across a SQL db?

    So I am trying to validate the file being uploaded to a database to check if the name exists or not prior to the upload. Is there a way to do that using the uploader?

     

    Any help would be appreciated.

    Khan

  •  12-14-2012, 4:46 PM 75465 in reply to 75461

    Re: How to validate a file being uploaded across a SQL db?

    Hi mskhan,

     

    You can get the upload file name at server side and client side both.

     

    at server side in event FileUploaded.

     

    1. protected void Uploader1_FileUploaded(object sender, UploaderEventArgs args) 
    2.     //get upload file name by args.FileName 
    3.     //if exists delete it by args.Delete(); 
     

    At client side in API CuteWebUI_AjaxUploader_OnSelect(files)

     

    1. <script> 
    2.     function CuteWebUI_AjaxUploader_OnSelect(files) { 
    3.         for (var i = 0; i < files.length; i++) { 
    4.             var name = files[i].FileName; 
    5.             if (file exist) { 
    6.                 files[i].Cancel(); 
    7.             } 
    8.         } 
    9.     } 
    10. </script> 
     

    Regards,

     

    Ken

  •  12-19-2012, 11:50 AM 75488 in reply to 75465

    Re: How to validate a file being uploaded across a SQL db?

    Ken,

     

    Thanks for getting back to me. I am trying something similar but its not working. I am trying to query into a Recordset and possibly find the file selected by the user within the recordset and if it doesn't exist then alert the user of it.

     

     

     

    1. <script>  
    2. function CuteWebUI_AjaxUploader_OnSelect(files) {  
    3.   
    4.                  <%  
    5.                 Set AdoCon=Server.CreateObject("ADODB.Connection")  
    6.                 Set AdoRec=Server.CreateObject("ADODB.Recordset")  
    7.                 AdoCon.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=*******;Initial Catalog=AFDDB_DEVY;Data Source=MOMENTUMTEST"  
    8.                 AdoCon.Open  
    9.                 AdoRec.Open "Select Custid from APPLICATION",AdoCon  
    10.                 str=AdoRec.GetString()  
    11.                   %>  
    12.   
    13.   
    14.                 for (var i = 0; i < files.length; i++) {   
    15.                 var name = files[i].FileName;   
    16.                 if (str=name) {   
    17.                     alert(name);  
    18.                     'files[i].Cancel();   
    19.                     }   
    20.                 }    
    21.                   
    22.                   
    23.                   <%  
    24.                 AdoRec.close  
    25.                 AdoCon.close  
    26.                 set AdoRec = Nothing  
    27.                 set AdoCon = Nothing  
    28.                     %>          
    29.                    
    30. </script>  
     I am just having it show me an alert but its not working. If I do a Response.Write(str) Then it does show me the query response from the database fine.

     

    Do you know the issue here?

     

    Thanks,

    Khan

  •  12-21-2012, 7:53 AM 75516 in reply to 75488

    Re: How to validate a file being uploaded across a SQL db?

    Hi,

     

    should be

     

     if (str==name) {  }

     

    Regards,

     

    Ken 

  •  12-21-2012, 2:08 PM 75518 in reply to 75516

    Re: How to validate a file being uploaded across a SQL db?

    Hi Ken,

     

    Thanks for that.

     

    However, it still does not show me the alert. Am I doing this wrong? Can this not be done in that function?

     

    Do you know of a better way?

     

    Thanks,

    Khan

  •  12-24-2012, 7:14 AM 75532 in reply to 75518

    Re: How to validate a file being uploaded across a SQL db?

    Hi mskhan,

     

    Please try the example page below.

     

    1. <%@ Language="VBScript" %>  
    2. <!-- #include file="aspuploader/include_aspuploader.asp" -->  
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
    4. <html xmlns="http://www.w3.org/1999/xhtml">  
    5. <head>  
    6.     <title>  
    7.         example  
    8.     </title>  
    9. </head>  
    10. <body>  
    11.     <div>                          
    12.             <form id="form1" method="POST">  
    13.             <%  
    14.             Dim uploader  
    15.             Set uploader=new AspUploader  
    16.             uploader.Name="myuploader"  
    17.             uploader.MultipleFilesUpload=true  
    18.             %>  
    19.             <%=uploader.GetString() %>  
    20.             </form>  
    21.     </div>  
    22. </body>  
    23. </html>  
    24. <script>   
    25.     function CuteWebUI_AjaxUploader_OnSelect(files)  
    26.         for (var i = 0; i < files.length; i++) {  
    27.             var name = files[i].FileName;  
    28.           alert(files[i].FileName);  
    29.         }   
    30.     }   
    31. </script>   
     

    Regards,

     

    Ken 

  •  12-26-2012, 11:07 AM 75547 in reply to 75532

    Re: How to validate a file being uploaded across a SQL db?

    Hi Ken,

     

    Hope you had a great Christmas. Thanks your reply.

     

    However, this still does not solve the issue at hand.

     

    1. <%    
    2.                Set AdoCon=Server.CreateObject("ADODB.Connection")    
    3.                Set AdoRec=Server.CreateObject("ADODB.Recordset")    
    4.                AdoCon.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=*******;Initial Catalog=AFDDB_DEVY;Data Source=MOMENTUMTEST"    
    5.                AdoCon.Open    
    6.                AdoRec.Open "Select Custid from APPLICATION",AdoCon    
    7.                str=AdoRec.GetString()    
    8.                  %>    
    9.    
    10.    
    11.                for (var i = 0; i < files.length; i++) {     
    12.                var name = files[i].FileName;     
    13.                if (str==name) {     
    14.                    alert(files[i].FileName);    
    15.                    'files[i].Cancel();     
    16.                    }     
    17.                }      
    18.                    
    19.                    
    20.                  <%    
    21.                AdoRec.close    
    22.                AdoCon.close    
    23.                set AdoRec = Nothing    
    24.                set AdoCon = Nothing    
    25.                    %>     
     

     

    I still am unable to validate across the database with the above code.

    For some reason str variable does not want to work against the name variable.

     

    Thanks,

    Khan 

     

  •  12-26-2012, 11:34 AM 75549 in reply to 75547

    Re: How to validate a file being uploaded across a SQL db?

    Also, can you tell me if this would work to grab the filename without the extension?

     

    1. for (var i = 0; i < files.length; i++) {  
    2.       var name = files[i].FileName;  
    3.       var extension = System.IO.Path.GetfileNameWithoutExtension(file[i].FileName);  
    4.          var extensionless = name.substring(0, name.Length - extension.Length);  
    5.          alert(extensionless);  
    6.                               
    7.      }  
     Hasn't worked me.

  •  12-31-2012, 11:18 AM 75563 in reply to 75549

    Re: How to validate a file being uploaded across a SQL db?

    Hi,

     

    1. <script>     
    2.     function CuteWebUI_AjaxUploader_OnSelect(files) {    
    3.         for (var i = 0; i < files.length; i++) {    
    4.             var name = files[i].FileName;    
    5.             var extension=files[i].FileName.substring(files[i].FileName.lastIndexOf("."));  
    6.             var nameNoExtension=files[i].FileName.substring(0,files[i].FileName.lastIndexOf("."));  
    7.             alert(extension);    
    8.             alert(nameNoExtension);  
    9.         }     
    10.     }     
    11. </script>     
     

    Regards,

     

    Ken 

  •  02-19-2013, 12:37 PM 76891 in reply to 75563

    Re: How to validate a file being uploaded across a SQL db?

    Is it possible using binding variable???
    Tech Support Outsourcing
  •  02-20-2013, 12:27 PM 76893 in reply to 76891

    Re: How to validate a file being uploaded across a SQL db?

    Hi maddybucks,

     

    Can you explain your question in detail? binding for what? for the uploader property? or the store location?

     

    Regards,

     

    Ken 

  •  04-18-2013, 4:04 AM 77243 in reply to 75549

    Re: How to validate a file being uploaded across a SQL db?

    mskhan:

    Also, can you tell me if this would work to grab the filename without the extension?

     

    1. for (var i = 0; i < files.length; i++) {  
    2.       var name = files[i].FileName;  
    3.       var extension = System.IO.Path.GetfileNameWithoutExtension(file[i].FileName);  
    4.          var extensionless = name.substring(0, name.Length - extension.Length);  
    5.          alert(extensionless);  
    6.                               
    7.      }  
     Hasn't worked me.

     

    same issue here, I've tried this one but it works here in my end.. maybe you got mistake to some things.

     

    regards,

    faxxx 

View as RSS news feed in XML