Can we set file extension and MaxsizeKb using javascript?

Last post 03-26-2009, 3:08 AM by DarShak_Boy. 13 replies.
Sort Posts: Previous Next
  •  02-16-2009, 7:27 AM 48831

    Can we set file extension and MaxsizeKb using javascript?

    Hi,
     
    Is there is any way to set file extension and MaxSizeKb using javascript.
     
    I am using uploadattachments control in ModelPopupExtender and calling this ModelPopupExtender popup on buttons click.
    So I want on button1 click control should allow file extension .jpg only and on button2 click .html only.
    I have tried following javascript code but not working.

    var cupControl = document.getElementById('ctl00_ContentPlaceHolderUI_CuteUploader');

    cupControl.setAttribute('Extensions','jpg');

     
    Please help.
     
    Regards,
    Yogesh
      
  •  02-16-2009, 8:37 AM 48833 in reply to 48831

    Re: Can we set file extension and MaxsizeKb using javascript?

    Yogesh,
     
    The server side also check the file extension,
     
    So we currently don't provide methods to change this property at client side.
     
    I suggest you place 2 uploaders, and show/hide it using style.display by javascript code.
     
    Regards,
    Terry
  •  02-16-2009, 9:48 AM 48847 in reply to 48833

    Re: Can we set file extension and MaxsizeKb using javascript?

     

    Hi Terry,

     

    We are reading xml file which will containing multiple image tags.

    These image tags are having file type attribute which decide which file extensions are allowed to upload for that image file. Previously we have added Uploader control in Gridview so if our xml is having 20 image tags then 20 Uploader controls were bound. This caused the size issue. Page size was about 4 mb. So we have decided to remove this Uploader control from Gridview and added it in ModelPopupExtender so it will be rendered only once. It reduced the page size to 600 kb. But we are not able to add file extension using JavaScript.

    If we use different control for file extension check then we will be back to our first issue as page size. So it is not possible for us to use that option.

    Please help.

     

    Regards,

    Yogesh

  •  02-16-2009, 10:09 AM 48849 in reply to 48847

    Re: Can we set file extension and MaxsizeKb using javascript?

    Yogesh,
     
    File extension allowed to upload and MaxsizeKb are required to set in the server side.
     
    If you want o use Javascript script to change the above setting, please use Ajax.

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  02-16-2009, 10:13 AM 48850 in reply to 48847

    Re: Can we set file extension and MaxsizeKb using javascript?

    ...

  •  02-16-2009, 11:22 AM 48861 in reply to 48831

    Re: Can we set file extension and MaxsizeKb using javascript?

    Yogesh,
     
    We have implemented a new property and javascript function for your request.
     
    We will release it today, and then I will tell you how to do.
     
    Regards,
    Terry
  •  02-16-2009, 10:26 PM 48894 in reply to 48861

    Re: Can we set file extension and MaxsizeKb using javascript?

    Yogesh
     
    Please download the control again.
     
    We have added new property DialogFilter.
     
    Please make sure you still need to use the ValidateOption.AllowedFileExtensions to prevent the users upload all kind of files (IFrame mode or hack)
     
    And you can set the DialogFilter by script:
    var uploader=document.getElementById("<%=Uploader1.ClientID%>");
    uploader.setdialogfilter("Images|*.jpg;*.gif|Documents|*.doc;*.txt");
     
     
    I will tell you how to limit the file size by script later.
     
     
    Regards,
    Terry
  •  02-22-2009, 11:39 PM 49087 in reply to 48894

    Re: Can we set file extension and MaxsizeKb using javascript?

    Hi Terry,
     
    Thanks.
    can i get the script for limiting the file size?
     
    Regards,
    Yogesh

  •  02-23-2009, 10:21 AM 49108 in reply to 49087

    Re: Can we set file extension and MaxsizeKb using javascript?

    Yogesh,
     
    Please check this sample code :
     
     <script type="text/javascript">
     function CuteWebUI_AjaxUploader_OnSelect(files)
     {
      for(var i=0;i<files.length;i++)
      {
       var file=files[ i ];
       if(file.FileSize!=-1)
       {
        if(file.FileSize>102400)
        {
         alert(file.FileName+" is larger then 100K");
         return false;
        }
       }
      }
     }
     </script>
     
    This is a client validation and you should validate the file size again at server side event.
     
    Regards,
    Terry
  •  03-24-2009, 12:29 PM 50220 in reply to 49108

    Re: Can we set file extension and MaxsizeKb using javascript?

    Hello,
     
    About this DialogFilter property. It seems it doesn't work with IE6 (only with IE7 and Firefox). Do you confirm? Because this is really annoying...
     
    And is the 'setdialogfilter' method still in the package? When I try to use this method, I get an "object does not support this property or method" error (it fails in all browsers).
    The version of the DLL I have is this one: "AjaxUploader 2.0 20090317"
     
    Thanks in advance,
     
    Dar
  •  03-24-2009, 12:40 PM 50222 in reply to 50220

    Re: Can we set file extension and MaxsizeKb using javascript?

    Dar,
     
    Yes, the 'setdialogfilter' is a member of the uploader , but only when it's be initialized.
     
    So you'd better call it on the CuteWebUI_AjaxUploader_OnInitialize event.
     
    DialogFilter only works for Flash/Silverlight, is the IE6 installed them?
     
    Regards,
    Terry
  •  03-25-2009, 2:57 AM 50253 in reply to 50222

    Re: Can we set file extension and MaxsizeKb using javascript?

    Ok, 'setdialogfilter' is working after initialization, thanks for the help!
     
    About the second point, you mean that to use 'DialogFilter' or 'setdialogfilter', the browser needs Flash or Silverlight installed??? Indeed, none of them is installed on my IE6.
  •  03-25-2009, 1:01 PM 50264 in reply to 50253

    Re: Can we set file extension and MaxsizeKb using javascript?

    Hi,
     
    Yes. DialogFilter is just for the browser plugins.
     
    If no plugin installed , the uploader would use the <input type="file"/> which do not support the filter.
     
    And the filter is just an helper property to let the users select the file easily.
     
    Please do not use it for security propose.
     
    Regards,
    Terry
     
  •  03-26-2009, 3:08 AM 50296 in reply to 50264

    Re: Can we set file extension and MaxsizeKb using javascript?

    Fine, thanks for the answer. Yes I understood that the filter is here to help users only.
View as RSS news feed in XML