10

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'.

1
  • 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
    Commented Feb 18, 2013 at 17:25

3 Answers 3

5

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
}
2
  • 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. Commented Feb 23, 2013 at 11:14
  • 1
    I've added a bounty of 50 - I think it's well worth it. Commented Feb 23, 2013 at 12:38
2

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>
2
  • There can't be a 'Where' tag in this CAML apparently. I can't really cater for the file type. Commented Feb 18, 2013 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
    Commented Feb 18, 2013 at 14:42
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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