Sunday, December 03, 2006

Restricting the number of File Attachments

It's quite simple to restrict the number of attachment in a specific InfoPath Form.With some knowledge of XPath expressions you can easily extend the InfoPath default behaviour.

Following these steps:
1. Create a new InfoPath form
2. Add a repeating section on your form (Design Task Pane > Controls) -> name: group1

3. Add an 'File Attachment' control in your repeating section -> name: field1
4. Double click on the 'repeating section' label to open its properties
5. Go to the Display tab and click on 'Conditional Formatting'
6. Click on the 'Add' button
7. Select 'The Expression' and enter following expression: 'count(my:field1) >= 10'
8. Apply following formatting: 'Don't allow users to insert or delete this control'
9. Click on OK (3 times)

10. Re-open the properties of the repeating section to open the conditional formatting again.
Have a look at the formatting you just have added ...
Your expression will be converted into another expression:
'Number of occurences of field1' is 'Greater than or equals to' 10

11. Test your form now and try to add 11 items ...


Geronimo said...

Just what I needed!
Thx dude

Sudhir Kesharwani said...

A Superb articleee...

thanks a ton...