Dan's Blog

Friday, July 28, 2006 - Limit file types in list item attachments

Posted in Sharepoint

To place file type restrictions on list attachments on a per list basis you need to add the OkAttach function from ows.js to the new item and edit item aspx pages for the list in question.

function OkAttach()
{
fileID = FileuploadString + FileUploadIndex;
fileInput = attachmentsOnClient.all(fileID);
filename = TrimWhiteSpaces(fileInput.value);
if (!filename)
{
var L_FileNameRequired_TXT = "You must specify a non-blank value for File Name.";
alert(L_FileNameRequired_TXT);
fileInput.focus();
}
else
{
var L_FileUploadToolTip_text = "Name";
oRow = idAttachmentsTable.insertRow();
RowID = 'attachRow' + FileUploadIndex;
oRow.id = RowID;
oCellFileName = oRow.insertCell();
oCellFileName.className = "ms-vb";
oCellFileName.innerHTML =  filename + "    ";
oCellControl = oRow.insertCell();
oCellControl.className = "ms-propertysheet";
oCellControl.innerHTML = "<.IMG SRC='" + document.all.RectGifUrl.value +
"'> <.a tabindex=1 href='javascript:RemoveLocal(" + RowID + ",\"" + fileID +
"\")'>" + L_Delete_Text + "<./a>";
fileInput.style.display="none";
++FileUploadIndex;
attachmentsOnClient.insertAdjacentHTML("beforeEnd",
"<.input tabIndex=1 type=file class=ms-long name=" +
FileuploadString + FileUploadIndex +
" title=" + L_FileUploadToolTip_text +">");
var theForm = fileInput.form;
theForm.encoding = 'multipart/form-data';
idAttachmentsRow.style.display='block';
ShowPart1();
}
}

Make sure you place the function inside the openning FORM tags and write your restriction code in the top of the ELSE block.



<- Last Page :: Next Page ->

About Dan's Blog

Dan Iveson
The blog of Dan Iveson. This will contain a mixture of technical articles related to Windows Sharepoint Services, Sharepoint Portal Server, other programming and family stuff.

Recent Posts

- Kite flying
- New Baby
- Nerds!
- MSN Presence
- Kings of Chaos

« July 2010 »
MonTueWedThuFriSatSun
 1234
567891011
12131415161718
19202122232425
262728293031 

Links

- Home
- View my profile
- Visit my website (http://www.daniveson.co.uk)
- Archives
- Friends
- Email Me
- My Blog's RSS
- My Blog's

Friends