Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
Bad characters in Web File Upload causes attachments to fail

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#BadCharactersInUploadedFiles or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/BadCharactersInUploadedFiles


When uploading files that have filenames with %, spaces, plusses, quotes, ampersands etc in them, cause the web page to not link correctly to the attachment, causing a 'This page cannot be found' error message. Here's how to stop it.





Create a File upload control as normal.

Save button should be something like:
<A HREF="javascript:checkFields()"><IMG SRC="save.gif" BORDER="0" ALT="Save"></a>

then in form's JS Header:

 

function checkFields()
{
var f = document.forms[0];
if ( f.Project.selectedIndex == 0  )  
               {
      alert ("You must select a Project")
 f.Project.focus();
}  
else if ( f.Title.value == "" )  
              {
      alert ("You must fill in a title")
 f.Title.focus();
}  
else
              {
 if ( getFileNames() )        
                              {  // passed validation
                                f.submit();
                               }
}
} // end of checkFields

function getFileNames()  
               {
var f = document.forms[0];
var allelements = f.elements.length;
for (i=0; i<allelements; i++)
                      {
 var doctype = f.elements[i].type;
 var docval = f.elements[i].value;
 if(doctype == "file")
                               {
  var start = docval.lastIndexOf("\\") + 1;
  var end = docval.length;
  var filename = docval.slice(start,end);
 
 // check filenames do not contain spaces, plusses or $ or & ' or " etc
                var BadChars = " !"+'"'+"£$%^&*()+'/\?,@`|¬"

                 for (c = 0; c < BadChars.length; c++)
                                              {
                       if (filename.indexOf(BadChars.substring(c,c+1)) !=-1  )
                                                      {
                       alert ("Found '"+BadChars.substring(c,c+1)+"' in\n "+ filename +"\n\n( space "+BadChars+" not allowed! )");
                       f.elements[i].focus();
                      return false;
                          }  // if bad char
  }  // end for badchars      
        } // element is of type file
 } // go through all elements
return true;
} //end of check files

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Lotus Notes 5 All-in-one Certification Exam Guide by Libby Schwarz, Ben Malekzadeh
Sort out your CLP with this book.
See at: Amazon.co.uk | Amazon.com |