There are a number of "special characters" that SharePoint will not allow in file/folder names (e.g. &, #, %). However, the browse function used by the Nintex "attachments" control allows users to select files with some of these characters in the file name. This guarantees a failure which the user cannot understand or recover from. Sequence of events is something like:
I realize that the file name issue is with SharePoint, but I would think that Nintex forms could parse file names used as forms attachments. If any characters are included in a file name which are know to fail in SharePoint, Nintex should inform the user immediately and instruct them to use a file name without the offending character(s). This way the problem is corrected before the form is submitted and the workflow proceeds as intended.
Anyone else have this issue? Any way to prevent users form attaching files with characters that SharePoint will reject?
Solved! Go to Solution.
Hi Ron,
had the same problem before, solved it by using some custom JavaScript function which I put on my Submit button to avoid attachments with special chars being submitted at all.
function ValidateAttachments() {
var isValid = true;
NWF$('.nf-attachmentsTable').find('tbody').find('tr').each(function() {
var file = NWF$(this);
var fileName = file.find('span')[0].innerText;
var match = (new RegExp('[~#%\&{}+\|]|\\.\\.|^\\.|\\.$')).test(fileName);
if (match) {
isValid = false;
alert('invalid file name:' + fileName);
}
});
return isValid;
}
On the "client click" settings of your submit button you put in "return ValidateAttachments()" et voila no more bad named attachments.
The regex used was provided by a colleague of mine, I'm sure it could be optimized, but was working fine for me. Nevertheless you should check the regex again to make sure no unwanted characters can be used.
Regards
Philipp
Philipp, I just gave this a quick try and it seems to work great!! I’ll do a bit more thorough testing over the next couple of days, but it looks like this will probably to the trick. Thanks so much for your prompt (and helpful) response!
Thanks,
Ron Pillsbury
Business Systems Analyst
Goodwill Industries of Northwest NC
2701 University Parkway, Winston-Salem NC 27105
T| 336.724.3625 x1333 C| 336.749.8009
rpillsbury@goodwillnwnc.org<mailto:rpillsbury@goodwillnwnc.org>
Hi Guys
I had a problem with this when in Edit mode, where the attachments become links and the span tag that is searched for is not there. So I made the following change:
Replaced line:
var fileName = file.find('span')[0].innerText;
with
Anyone else having an issue that if the file has a validation error that the delete button next to the bad file does not work? It works for the other files just not the one with the error.
Great workaround for a feature that should be built-in (Vote it up here: https://nintex.uservoice.com/forums/229406-2-nintex-forms-for-sharepoint/suggestions/8079168-fix-att....
I added an else to accommodate resetting the yes/no field so when they correct the file attachment the validation stops failing. (BadAttachment is my variable name on my Yes/No field).
function ValidateAttachments() {
var isValid = true;
NWF$('.nf-attachmentsTable').find('tbody').find('tr').each(function() {
var file = NWF$(this);
var fileName = file.find('span')[0].innerText;
var match = (new RegExp('[~#%\&{}+\|$<>?:\\\/*"]')).test(fileName);
if (match) {
isValid = false;
alert('Attachment(s) may contain invalid characters, please rename and reattach the file:\n\n ' + fileName);
NWF$("#" + BadAttachment).prop('checked',true);
}
else
{
NWF$("#" + BadAttachment).prop('checked',false);
}
});
return isValid;
}
Thank you Philipp and Adrian! This works great, the change for Edit mode is also very helpful.
The above regular expression seems to be missing / : * ? " < and > but I think that's because those characters are not allowed in files (Explorer) anyway? (Though the same goes for \ and | but those are included.) I also noticed + is included, but this character is actually allowed in a file!
Consecutive . and/or a . at the end/beginning of a filename are included in the regex, however not _ at the beginning of a file. The underscore is allowed, but it will hide the file - I suppose this applies to a library only and not attachments in a list?
Hi Yvette,
when I upload a file having a name beginning with an underscore ("_") the file remains visible for me, not only inside a doc library but also as an attachment of a list item.
Regards
Philipp
Hi Philipp,
You're right about the underscore. I tested this and came up with the same result. I'm not sure how that works...
Something else I noticed with the above JavaScript: the validation function overwrites the validation that I configured on the form's attachment control itself. I can now also submit the form without adding the minimum of 1 attachment.
My colleague and I came up with the following solution:
function ValidateAttachments() {
var isValid = true;
var elm = NWF$('.nf-attachmentsTable');
if (elm.length > 0 && elm.find('tr').length >= 1)
{
isValid = true;
}
else
{
isValid = false;
alert('Gelieve de specificatie toe te voegen.');
return isValid;
}
NWF$('.nf-attachmentsTable').find('tbody').find('tr').each(function() {
var file = NWF$(this);
var fileName = "";
if (typeof file.find('span')[0] != "undefined")
{
fileName = file.find('span')[0].innerText;
}
else
{
fileName = file.find('a')[0].innerText;
}
var match = (new RegExp('[~#%\/&:"?<>*{}|]|\\.\\.|^\\.|\\.$')).test(fileName);
if (match)
{
isValid = false;
alert(fileName + ' bevat niet toegestane tekens, zoals / \ : * ? % & " en #.\nGelieve deze aan te passen en het bestand opnieuw toe te voegen.');
}
});
return isValid;
}
I thought I would post this as it might help somebody else. Alerts are in Dutch but you get the point.
Regards,
Yvette
I have a problem with Your solution. When client click of submit button is configured with 'return ValidateAttachments() then other Custom validation functions configured in Control Settings of other controls are no longer executed.
Anywhere else have this problem or is it a problem with NintexForms Version (here 2.6.0.0)?
Kind regards
Manfred