Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rick 92 posts 278 karma points
    Feb 12, 2013 @ 16:56
    Rick
    0

    File Upload Control - Contour 2

    Hi,

    I am using a File Upload control on my Contour form and was just wondering if I can validate any file that is picked.

    When I use other field types, such as the Textbox control, I can see the option to apply regex. However, there is no option to add this on the File Upload control.

    I was thinking of incorporating jQuery validate; however, all that would be required to get around this is to disable JavaScript.

    Can anyone help?

    Many thanks

    Rick

  • Comment author was deleted

    Feb 12, 2013 @ 17:08

    Using the razor macro you can hook into the form validation... it's even easier when using code first check out the examples here http://www.nibble.be/?p=205

     

  • Rick 92 posts 278 karma points
    Feb 12, 2013 @ 17:48
    Rick
    101

    Tim, thanks for the lightning quick reply!

    As I'm using Contour 2, I can't use the razor macro to hook into form validation. Therefore, I found this 'addon' to allow me to achieve what I wanted.

    http://our.umbraco.org/projects/backoffice-extensions/cogworks-cogfilteredupload

    However, a word of warning for others when using this 'addon'... I had to alter this line in the class:

    string dir = Configuration.Path + "/files/" + this.AssociatedField.Form.ToString() + "/";

    to this:

    string dir = Configuration.Path + "/files/" + this.AssociatedField.Form.ToString() + "/" + Guid.NewGuid().ToString() + "/";

    Otherwise, each time a file was uploaded with the same name, it would be overwritten in the directory. The re-worked line creates a new folder with the name of Guid.NewGuid() and drops the uploaded file into that specific folder.

    Hope this helps someone out there!

    Rick

Please Sign in or register to post replies

Write your reply to:

Draft