I would like to programatically add alert to folders inside a sharepoint list. I have found how to set alerts to a list and this works perfect.
Could someone please help me on how to set alerts to a specific folder which is inside a list.
Below is the code i currently have which sets alerts only to the list.
using (SPSite site = new SPSite("http://site/"))
{
using (SPWeb web = site.OpenWeb())
{
SPUser user = web.SiteUsers["domain\\user"];
SPAlert newAlert = user.Alerts.Add();
newAlert.AlertType = SPAlertType.List;
newAlert.List = web.Lists["Documents"];
newAlert.EventType = SPEventType.All;
newAlert.AlertFrequency = SPAlertFrequency.Immediate;
//passing true to Update method will send alert confirmation mail
newAlert.Update(true);
}
}
Your help will be much appreciated
THIS QUESTION IS RESOLVED! PLEASE SEE MY POST BELOW WITH THE LINK - SEE - LINK
That's not possible out of the box, but after googling I found an interesting possibility though, check out Mike Walsh's answer on this post, it entails creating a view in the folder and then attaching the alert to that view.
You need to update the line with
newAlert.List = web.Lists["Documents"];
With
SPFolder fldr = web.GetFolder("/ListName/FolderName");
newAlert.Item=fldr.Item;
Also note that Folder is also another item.
Related
I have the requirement to add performance point filter web part and report view web part to a page in SharePoint 2010 programmatically. I can add both web parts to the page however I have no idea on how to setup connection between them, i.e. for filter web part to be able to send its value to the report view web part.
Any help would be much appreciated.
Found the solution to this :)
What I did was when I create the connection using SPConnectWebParts, I use TransformableBIDataProviderTransformer object, e.g.
var list = new List<TransformProviderConsumerRecord>();
var transformer = new TransformableBIDataProviderTransformer();
var tpcRecord = new TransformProviderConsumerRecord();
tpcRecord = "SqlReportViewUniqueParameterIdSI1";
tpcRecord.ProviderParameterName = "FilterValues";
tpcRecord.DisplayColumnName = "DisplayValue";
tpcRecord.MappingId = (new Guid()).ToString();
tpcRecord.ProviderParameterDisplayName = "PerformancePoint Values";
tpcRecord.TypeFullName = "System.String";
tpcRecord.ValuesColumnName = "DisplayValue";
list.Add(transformProvConsRecord);
ProviderConsumerTransformations provConsTransf = new ProviderConsumerTransformations(list);
var tcr = new TransformerConfigurationRecord(provConsTransf, new TransformConditionalVisibilityRecord());
transformer.ConfigurationState = tcr;
wpm.SPConnectWebParts(providerWp, providerConnection, consumerWp, consumerConnection, transformer);
Where providerWP is Performance Point filter web part amd consumerWp is Performance Point Report
I've a SharePoint 2010 page with a list. The list has several items and a field named "Department" and must filter items based on user's department value retrieved from user profile.
To do this I've created a feature which upon activation adds UserContextFilterWebPart to the page and makes connection between UserContextFilterWebPart and XsltListViewWebPart. After the feature is activated I can see in the page design mode that connection is established but the list gets empty. Then I open web part's menu, choose "Connections" then "Send Filter Values To" and click "List1". When dialog appears I do nothing but only click "Finish" button and it begins to work fine. Can anybody please explain me why the connection begins to work only if I do that manual extra action? What must be done to fix?
I tried different way when List.Views[0].Query property is set to appropriate CAML query and it also works fine. But I'm told that it's not a good approach because of performance and parallel tasks issues. Is it really bad course of action?
Below is the code for 2 different approaches.
Thanks in advance!
1-s variant with UserContextFilterWebPart:
SPSite Site = new SPSite(URL);
SPWeb Web = Site.OpenWeb();
SPLimitedWebPartManager WPM = Web.GetLimitedWebPartManager(URL, PersonalizationScope.Shared);
XsltListViewWebPart List = WPM.WebParts[0] as XsltListViewWebPart;
UserContextFilterWebPart UCFWP = new UserContextFilterWebPart();
UCFWP.Title = "Current User Filter";
UCFWP.AllowEdit = true;
UCFWP.FilterName = "Current User";
UCFWP.SendEmptyWhenNoValues = true;
UCFWP.AllowClose = true;
UCFWP.ExportMode = WebPartExportMode.All;
UCFWP.AllowConnect = true;
UCFWP.AllowHide = true;
UCFWP.ProfilePropertyName = "Department";
UCFWP.ValueKind = UserContextFilterValueKind.ProfileValue;
UCFWP.ZoneID = "Main";
WPM.AddWebPart(UCFWP, UCFWP.ZoneID, 1);
WPM.SaveChanges(UCFWP);
ConsumerConnectionPointCollection consumerConnections = WPM.GetConsumerConnectionPoints(List);
ConsumerConnectionPoint addConsumerConnPoint = consumerConnections["DFWP Filter Consumer ID"];
ProviderConnectionPointCollection providerConnections = WPM.GetProviderConnectionPoints(UCFWP);
ProviderConnectionPoint addProviderConnPoint = providerConnections["ITransformableFilterValues"];
TransformableFilterValuesToParametersTransformer trans = new TransformableFilterValuesToParametersTransformer();
trans.ConsumerFieldNames = new string[] { "Department" };
trans.ProviderFieldNames = new string[] { "Department" };
SPWebPartConnection newConnection = WPM.SPConnectWebParts(UCFWP, addProviderConnPoint, List, addConsumerConnPoint, trans);
WPM.SPWebPartConnections.Add(newConnection);
2-nd variant with CAML query (intended to be used not in a feature but in a web part):
SPSite Site = new SPSite(URL);
SPWeb Web = Site.OpenWeb();
SPLimitedWebPartManager WPM = Web.GetLimitedWebPartManager(URL, PersonalizationScope.Shared);
XsltListViewWebPart List = WPM.WebParts[0] as XsltListViewWebPart;
SPUser CurrentUser = Web.CurrentUser;
SPServiceContext context = SPServiceContext.GetContext(Site);
UserProfileManager upm = new UserProfileManager(context, false);
UserProfile up = upm.GetUserProfile(CurrentUser.RawSid);
String UserDepartment = up["Department"].Value.ToString();
SPView ListView = Web.Lists["List1"].Views[0];
ListView.Query = "<Where><Eq><FieldRef Name='Department' /><Value Type='Text'>" + UserDepartment + "</Value></Eq></Where>";
ListView.Update();
I had a similar problem of connecting two web parts. I found the answer here: http://kvdlinden.blogspot.dk/2011/02/programmatically-connect-two.html
Note that that post describes how to do it with two XsltListViewWebParts. In order to use it in your case I suggest that you:
Create the connection manually,
Use PowerShell to get a SPLimitedWebPartManager for the page,
Use the manager to iterate through the manager.SPWebPartConnections,
And find the ProviderConnectionPointID for your connection,
Use that ID in the code shown in the post.
Also remember to setup the transformer - you can find this also from the SPWebPartConnections.
Next time you activate your feature you should have a connection equal to the one you made by hand.
I need to find out (programmatically) what term set is used by a certain user profile property, but I can't figure out how to do that. Any ideas are highly appreciated!
Finally, figured it out:
SPSite site = new SPSite(url);
SPServiceContext context = SPServiceContext.GetContext(site);
var userProfileConfigManager = new UserProfileConfigManager(context);
ProfilePropertyManager profilePropertyManager = userProfileConfigManager.ProfilePropertyManager;
CorePropertyManager corePropertyManager = profilePropertyManager.GetCoreProperties();
CoreProperty property = corePropertyManager.GetPropertyByName(propertyName);
TermSet ts = property.TermSet; // DONE!
I am trying to insert new ListItems in a Sharepoint 2010 List already created. The code I'm using is:
ClientContext ctx = new ClientContext("http://bigboss/sites/presidencia");
Web thisWeb = ctx.Web;
ctx.Load(thisWeb);
List processosList = ctx.Web.Lists.GetByTitle("Processos");
ListItemCreationInformation lici = new ListItemCreationInformation();
ListItem liNovoProcesso = processosList.AddItem(lici);
liNovoProcesso["Title"] = processo.Identificador;
liNovoProcesso["IdentificadorProcesso"] = processo.Identificador;
liNovoProcesso["DescricaoProcesso"] = processo.Descricao;
liNovoProcesso["NotasObservacoesProcesso"] = processo.NotasObservacoes;
liNovoProcesso["SituacaoProcesso"] = processo.Situacao;
processosList.Update();
ctx.ExecuteQuery();
This code runs without erros or exceptions, but the list isn't showing the items. I've already tried to change Field names to trigger an error, just to be sure that the code its running, and it throws an error, like expected!
Any tips, please?
thanks,
José Cruz
Are you missing ?
liNovoProcesso.Update();
You should update the ListItem object instead of List.
I need the information about the SharePoint document library. Namely, I need the info whether the versioning is turned on or off and if the "require check out" option is selected. I have to use SharePoint web services.
I have looked up in Versions.asmx, Lists.asmx and SiteData.asmx, but found no method or properties that suit my needs.
Could anyone help me out please? Thanks.
You will need to make use of the lists.asmx GetList method. It returns all of the metadata about a list.
Here's some code I've been using in combination with Linq to XML:
Private _serviceRefrence As SharePointListsService.ListsSoapClient
Dim endPoint As New ServiceModel.EndpointAddress(_serviceURL)
Dim ListID as Guid = New Guid("<<Your List Guid>>")
_serviceRefrence = New SharePointListsService.ListsSoapClient("ListsSoap", endPoint)
_serviceRefrence.ClientCredentials.Windows.ClientCredential = Credentials
_serviceRefrence.ClientCredentials.Windows.AllowedImpersonationLevel = Security.Principal.TokenImpersonationLevel.Impersonation
Dim results As XmlElement = _serviceRefrence.GetList(listID.ToString())
Dim parserResults As XDocument = XDocument.Parse(results.OuterXml)
Dim listinfo = (From list In parserResults.Descendants(XName.Get("List", "http://schemas.microsoft.com/sharepoint/soap/")) _
Select New With {.RequireCheckout = list.Attribute("RequireCheckout").Value, _
.ModerationEnabled = list.Attribute("EnableModeration").Value, _
.VersioningEnabled = list.Attribute("EnableVersioning")}).Single()
Hope this helps!