How to get file size in Client Machine using scripts?

Discussion in 'ASP .Net Security' started by Nabanit Barooah, May 10, 2006.

  1. Hi,

    We are working on a Web Application (in ASP.NET). The application basically
    deals with uploads from the client machine. We need to check the size of the
    file that will be uploaded. The size must be known in the client - side of
    the application, so that proper validations can be done before the user tries
    to upload the file.

    One way of resolving this issue is by using File System Object in JavaScript
    or using Create Object in VBScript. But this has got some security issues -
    we need to enable an Internet Option "Initialise and Script ActiveX object
    not marked as safe". We are looking for any other alternative approach. It
    will be very helpful if anyone can suggest some solutions.
    Code we are using in JavaScript:

    var objFSO, objFile, fileSize;
    objFSO = new ActiveXObject("Scripting.FileSystemObject");
    objFile = objFSO.GetFile(document.all.item("File1").value);
    fileSize = objFile.Size;

    Regards,
    Nabanit Chandra Barooah
     
    Nabanit Barooah, May 10, 2006
    #1
    1. Advertising

  2. You can't access the client file system from Javascript. You have to put
    an ActiveX component or Java applet on the page to get that kind of
    access. That of course means that the user has to accept that the
    component is started.

    Nabanit Barooah wrote:
    > Hi,
    >
    > We are working on a Web Application (in ASP.NET). The application basically
    > deals with uploads from the client machine. We need to check the size of the
    > file that will be uploaded. The size must be known in the client - side of
    > the application, so that proper validations can be done before the user tries
    > to upload the file.
    >
    > One way of resolving this issue is by using File System Object in JavaScript
    > or using Create Object in VBScript. But this has got some security issues -
    > we need to enable an Internet Option "Initialise and Script ActiveX object
    > not marked as safe". We are looking for any other alternative approach. It
    > will be very helpful if anyone can suggest some solutions.
    > Code we are using in JavaScript:
    >
    > var objFSO, objFile, fileSize;
    > objFSO = new ActiveXObject("Scripting.FileSystemObject");
    > objFile = objFSO.GetFile(document.all.item("File1").value);
    > fileSize = objFile.Size;
    >
    > Regards,
    > Nabanit Chandra Barooah
     
    Göran Andersson, May 13, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    6,635
    Matt Humphrey
    Jun 3, 2006
  2. Ramdas
    Replies:
    20
    Views:
    771
    Lawrence D'Oliveiro
    Jan 10, 2007
  3. davidj411
    Replies:
    0
    Views:
    551
    davidj411
    Jun 27, 2008
  4. Poppy

    Get file size on client machine ?

    Poppy, Apr 13, 2004, in forum: ASP General
    Replies:
    1
    Views:
    141
    Matt Foster
    Apr 13, 2004
  5. PerlFAQ Server
    Replies:
    0
    Views:
    130
    PerlFAQ Server
    Apr 9, 2011
Loading...

Share This Page