ASP Upload

Discussion in 'ASP /' started by sladmin, Jun 22, 2009.

  1. sladmin CSNM Reseller

    Hi guys,

    I'm just working on an upload section of a particular website at the moment and would like to check that the file extension is correct before upload. However, without using ajax I have to use more than one page with if statements to make it work.

    My question however, is can I delay the upload but save the data in variables, or do I HAVE to upload the file firstly, check it properties and then delete it should it be wrong?

    I just think it might lag the server if everytime someone uploads a file (whether the correct files or not) and then either delete them using the System File Object or insert the file information into the database.

    Any ideas because I've tried delaying the upload file until after the check pages, but it doesn't seem as if you can pass variables into a file field.

    Ohh and the files will never be any large than about 5mb each.

    Many thanks,
  2. siphilp CSNM Customer

    You could always put an onchange event on the file textbox, put it through a regular expression that grabs the file extension and if it doesn't match then present user with a error but that would rely on javascript being enabled...

    You could do the check server side before saving the file ( :S

    Uploader = asp:FileUpload
    [SIZE=2]var sFileExt = Functions.Files.ReturnFileExtension(Uploader.PostedFile.FileName.Trim());[/SIZE]
    var FileObjectDetails = new FileObjectDetails(size,ext,type,name,guid);
    [SIZE=2]Uploader.PostedFile.SaveAs(Server location);[/SIZE]
    //problem saving details to db
    [SIZE=2]lblMessage.Text = "Wrong File Type";[/SIZE]
  3. siphilp CSNM Customer

  4. Ben Collier CSNM Customer

  5. diego CSNM Customer

  6. diego CSNM Customer

    PS.: you can't pass variables along with the file field but you CAN pass variables in the query string.

    Basically, you can POST the binary data (the files) to an URL with a query string, like this:
  7. sladmin CSNM Reseller

    Hi Diego,

    Unfortunately in order to use the querystring method you will need to use a request.querystring to call the information. Anything to do with a request method is not allowed since the upload method used interfers with this.

    I got around this by using a session variable across two pages, which then went onto the upload page.

    Thanks for the help though guys :)
  8. Mark Voss CSNM Customer

    Thanks for this info Adam, just needed to do something that needed variables passing between a form and an ASPUpload script and found this thread ;-)
  9. sladmin CSNM Reseller

    No problem! Glad I could help in some way :)

Share This Page