Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have created an alert for a user against a list (more specifically, a document library).

I want the user to be notified of all changes regarding list items (documents) and not any sub folders.

What I've Tried:

SPAlert alert = new SPAlert();
alert.Filter = "<Query><Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq></Query>";

All items (including folders) are included in any e-mail alerts to the user.

To clarify, when a folder is created within a doc library with an alert against it - the user should not be notified.

When a document is created in that same document library, they should be.

I've also tried:

<Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq>

(Note the <Query> tags have been omitted).

It is currently not an option to specify what content types I do want to include in the alert. I just want to omit any items of content type 'Folder'.

share|improve this question
1  
What if you used a search alert instead of a list alert. Could you make a search that returns just the docx files in a doc lib? if so create an alert on that search and see if it does the trick? –  ghangas Feb 18 '13 at 17:25
add comment

3 Answers 3

up vote 5 down vote accepted

Why don't you use a SPAlertHandler to change how alerts work for this list? Then you can decide when an alert is sent or not in C# code.

http://msdn.microsoft.com/en-us/library/bb897791(v=office.14).aspx

public override bool OnNotification(SPAlertHandlerParams ahp)
{
    try
    {
        using (SPSite site = new SPSite(ahp.siteUrl + ahp.webUrl))
        {
            using (SPWeb web = site.OpenWeb(ahp.webUrl))
            {
                ahp.headers["from"] = site.WebApplication.OutboundMailSenderAddress;  //Unsure if this is needed
                SPList list = web.Lists[ahp.a.ListID];
                SPListItem item = list.GetItemById(ahp.eventData[0].itemId);
                //SPAlert alert = web.Alerts[ahp.a.ID];

                if (item.Folder == null)  //Item is not a folder
                {
                    SPUtility.SendEmail(web, ahp.headers, ahp.body);  //Send Alert
                }
            }
        }
    }
    catch (System.Exception ex)
    {
        //Handle error
    }
    return false;  //Tell SharePoint that the Alert is already processed
}
share|improve this answer
    
Steve this looks very very interesting. I'll read the link now, because up until now I've got no other approach to work. Thanks very much, +1. I'll mark accordingly. –  DeeMac Feb 23 '13 at 11:14
1  
I've added a bounty of 50 - I think it's well worth it. –  DeeMac Feb 23 '13 at 12:38
    
Thanks, I'm glad it worked out for you. –  Steve Lineberry Feb 23 '13 at 14:13
add comment

I went through this process myself (as you may have seen from my answer to your other question here)

Basically, alert views can't be based on certain default content types. My full adventure figuring that out, as well as a work-around and some potentially helpful code, is here for those who are curious. It involves creating a custom content type based on the folder and changing all folders to that new content type, then filtering based on it.

share|improve this answer
add comment

I'd say you would try to filter by file type instead. The following would get you Word documents with file extension docx only:

<Where>

    <Eq>

        <FieldRef Name='File_x0020_Type' />

        <Value Type='text'>docx</Value>

    </Eq>

</Where>
share|improve this answer
    
There can't be a 'Where' tag in this CAML apparently. I can't really cater for the file type. –  DeeMac Feb 18 '13 at 14:37
3  
And if you loose the outer where, what happens then? I guess there is an embedded <where> somewhere in your code, or in the object you're referencing –  Benny Skogberg Feb 18 '13 at 14:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.