Environment: SP2010 Enterprise, VS2012
I've been using C# to programmatically create alerts for various users and implementing the alert.Filter property to assign filters that point to specific directories. It's simple enough to create a variable for the path to insert into the filter, but when it comes to the username, passing a variable in its place does not seem to work using any method I have tried. CAML (or at least the pseudo-CAML used in filters) likes the user's name to actually be the name field (in this case, pulled from AD) not the account name. So after a little playing around I figured out how to turn that into a variable to pass into the filter like this:
string userName = vUser.Name; string oFilter = ("<Query><And><Or><Eq><FieldRef Name='ItemFullUrl'/><Value type='string'>" + fullPath + "</Value></Eq><BeginsWith><FieldRef Name='ItemFullUrl'/><Value type='string'>" + fullPath + "/</Value></BeginsWith></Or><Neq><Value type='string'>" + userName + "</Value><FieldRef Name='Editor/New'/></Neq></And></Query>)"); oAlert.Filter = oFilter;
The user.Name property outputs a name that matches the format in the CAML filter of a working alert I examined. If I type the name directly into the filter it works fine, but when I try to pass it as a variable it breaks, even if I explicitly set the variable to "User Name".
Is there some part of how the filter/string works that I'm not accounting for? Every search I've done online has said this method should work, in theory. My goal is simply to make the alert apply only to changes made by other users, is there perhaps another way to accomplish that?
Any advice is greatly appreciated!