SOS: How to validate the attachment size of picture control - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

SOS: How to validate the attachment size of picture control

Last post 07-12-2019 10:11 AM by Ana313. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 09-12-2007 10:47 AM

    SOS: How to validate the attachment size of picture control

    Hi,

    Can anybody help how to extract/find attached picture or file size of file or picture control at design time or using code behind (.Net or J/Vb script) at some event handler. Basically i have a form which is having many file/picture attachment controls in different sections, But while submitting i want to make sure that attachment size is limited to some KBs. Any help would be greatly appreciated. 

     

  • 09-12-2007 10:47 PM In reply to

    Re: SOS: How to validate the attachment size of picture control

    You can either do it the hard way, as in decoding the header (see more here: http://www.infopathdev.com/forums/p/1474/6839.aspx#6839).

    Or you can just make the following claim: binary files are encoded with BASE-64 encoding, so you only have 3 bytes get encoded with 4. That means that the original size of the file is the string length of the XML field * 0.75 (approximately because there is the header as well but it is negligeable).

    With this, you might simply use declarative validation instead of writing code, simply say "if string-length of this control is greater than this value, it's an error".

     

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 09-13-2007 11:45 AM In reply to

    Re: SOS: How to validate the attachment size of picture control

    Dear Davidair,

    Thanks for your reply, but i am not getting you point, should i use some rule, or use this validation in script? in rule i can't use integer value. 

     

  • 09-13-2007 12:28 PM In reply to

    Re: SOS: How to validate the attachment size of picture control

    Use declarative validation...

    Suppose your attachment field is called field1 and you don't want it to be bigger than 100k, that means that length of the piture field cannot be more than 136533 charaters (assuming UTF8).

    1. Open the Data Source pane
    2. Double-click on field1 to bring up its properties
    3. In Validation, add a new condition
    4. Select Expression, type this expression in: string-length(.) > 136533
    5. Enter the text to be displayed when the error condition occurs

    Now when you edit the form, if the image is too big, you will get an error validation and the user will be warned on save.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 09-13-2007 12:47 PM In reply to

    Re: SOS: How to validate the attachment size of picture control

    Dear Davidair,

    You are the champion, you saved my life :). I went into picture control properties in IP 2007, then in rules, added required rule as an expression and it worked.

    Thank you very much as i was thinking of hell of Base64 encoding in VSTA.

     

  • 09-13-2007 11:03 PM In reply to

    Re: SOS: How to validate the attachment size of picture control

     

    I just learned something new. This is a sweet trick for limiting image size.
    Patrick Halstead
    Project Manager at Qdabra
  • 09-13-2007 11:32 PM In reply to

    Re: SOS: How to validate the attachment size of picture control

     I am somehow unable to restrict user to attach picture. Message is displayed "Picture is too big" but picture is attached.

  • 09-14-2007 03:41 AM In reply to

    Re: SOS: How to validate the attachment size of picture control

    I some how managed it by setting field value to 0 in actions and another action wit ha msgbox "Too big picture"

  • 11-07-2015 10:31 PM In reply to

    • hajjaj
    • Not Ranked
    • Joined on 11-05-2015
    • Posts 2

    Re: SOS: How to validate the attachment size of picture control

    it works with every except me :'( , what is the issue with it ?
  • 11-09-2015 03:00 PM In reply to

    Re: SOS: How to validate the attachment size of picture control

    This was for IP 2007, but I just successfully tested with 2013. Can you elaborate about what is not working?
    Hilary Stoupa

  • 11-09-2015 09:22 PM In reply to

    • hajjaj
    • Not Ranked
    • Joined on 11-05-2015
    • Posts 2

    Re: SOS: How to validate the attachment size of picture control

    it is not validating , when I submit , its is not validating the size at all!
  • 11-10-2015 09:32 AM In reply to

    Re: SOS: How to validate the attachment size of picture control

    Validation should happen as soon as the file is attached. Try making the number in your expression much smaller for the sake of experimentation, preview, and attach a large file and see if the control gets a red outline.
    Hilary Stoupa

  • 07-12-2019 10:11 AM In reply to

    • Ana313
    • Not Ranked
    • Joined on 07-12-2019
    • Posts 1

    Re: SOS: How to validate the attachment size of picture control

    Hi.. i know this post is very old. but I want the similar requirement. How to add the validation when the file size attached is greater than 10kb in info-path form. I am using Infopath form 2013 and SharePoint 2016 on premise. I have tried the base 64 coding by using string length and the javascript on new item page. But both didnot worked. Your help would highly appreciate.
Page 1 of 1 (13 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.