locked
verify item has an attachment RRS feed

  • Question

  • I need to verify that an item has an attachment in the ItemAdding event.  I've made several attemps to get this to work, but I'm having no luck.  Any ideas? 

    Imports System  
    Imports System.Collections.Generic  
    Imports System.Text  
    Imports Microsoft.SharePoint  
    Imports System.Diagnostics  
     
        Class ListValidationEventReceiver  
            Inherits SPItemEventReceiver  
        Public Overloads Overrides Sub ItemAdding(ByVal properties As SPItemEventProperties)  
                      
            If properties.AfterProperties("AttachmentURL").ToString().Length < 1 Then 
                properties.Status = SPEventReceiverStatus.CancelWithError  
                properties.ErrorMessage = "You must attach a copy of the invoice to this item" 
                properties.Cancel = True 
            End If 
     
        End Sub 
        End Class 
    Friday, November 7, 2008 8:47 PM

Answers

  • As you have probably tried, and seen, there is no way of retrieving this information in the ItemAdding event handler - a bit of an oversight I think!! An alternative could be to perform the check in ItemAdded and then perform a redirect to another page if attachment is not there (I have not tried this but think it should work) forcing the user to add one (although you would probably have to create this page yourself?)

    Stu
    • Marked as answer by MDHunt Monday, November 10, 2008 1:09 PM
    Friday, November 7, 2008 9:56 PM