I have a two views of my List and two SharePoint groups. Only one List view is visible depending on the user logged in according to his group.
I am using SitePage
and added a WebPartZone
to it. In the Feature Activated method I used SPLimitedWepartManager
and added two XSLTListViewWebPart
and added the views accordingly. Also set target Audience for each XSLTListViewWebPart
. and added the XSLTListViewWebParts to the SPLimitedWepartManager
.
When I deploy the solution I get an error:
Error occurred in deployment step 'Activate Features': UserProfileApplicationNotAvailableException_Logging :: UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does not have 64961d83-fdf2-4d48-8137-8860f07e64b8
I have added the code below:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = null;
site = properties.Feature.Parent as SPSite;
string strG = "Global Users";
string strR = "Regional Users";
SPGroup Ggroup = null;
SPGroup Rgroup = null;
SPList list = null;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
Ggroup = web.Groups[strG];
Rgroup = web.Groups[strR];
using (SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(web.Url + "/SitePages/CustomSitePages/RequestSitePage.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
//For Regional Users
XsltListViewWebPart xlvWebpart_Regional = new XsltListViewWebPart();
list = web.Lists.TryGetList("RequestList");
SPView listView_R = null;
SPListItem listItem_R = null;
listItem_R = list.Items.Add();
SPServiceContext context = SPServiceContext.GetContext(site);
listView_R = list.Views["RegionalUsers"];
xlvWebpart.ListId = list.ID;
xlvWebpart_Regional.ViewGuid = listView_R.ID.ToString();
xlvWebpart_Regional.Title = "Regional Users";
AudienceManager audienceManager_R = new AudienceManager(context);
// ERROR in the below Line of Code. Project gets deployed when the below line is commented
xlvWebpart_Regional.AuthorizationFilter = string.Format("{0};;;;", audienceManager_R.GetAudience(strR).AudienceID); // ERROR in this Line of Code
wpManager.AddWebPart(xlvWebpart_Regional, "UsersZone", 0);
wpManager.SaveChanges(xlvWebpart_Regional);
//For Global Users
XsltListViewWebPart xlvWebpart_Global = new XsltListViewWebPart();
SPView listView_G = null;
SPListItem listItem_G = null;
listItem_G = list.Items.Add();
listView_G = list.Views["GlobalUsers"];
xlvWebpart_Global.ListId = list.ID;
xlvWebpart_Global.ViewGuid = listView_G.ID.ToString();
xlvWebpart_Global.Title = "Global Users";
AudienceManager audienceManager_G = new AudienceManager(context);
// ERROR in the below Line of Code. Project gets deployed when the below line is commented
xlvWebpart_Global.AuthorizationFilter = string.Format("{0};;;;", audienceManager_G.GetAudience(strG).AudienceID); // ERROR in this Line of Code
wpManager.AddWebPart(xlvWebpart_Global, "UsersZone", 0);
wpManager.SaveChanges(xlvWebpart_Global);
web.Update();
}
}