November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Fixed this on my own !!
//Remove trailing '/' character in the end
privatelink= privatelink.Remove(privatelink.LastIndexOf("/"));
var matchingPrivateLinkCounter=userPage.PrivateLinks.Where(x => x.Href == privatelink).Count();
if ( matchingPrivateLinkCounter> 0)
{
var objLinkItem = userPage.PrivateLinks.Where(x => x.Href == privatelink).Single();
//removing private link from the collection
userPage.PrivateLinks.Remove(objLinkItem);
}
Hi,
I am using episever cms 6 r2 version.
I am trying to remove a link item from link item collection property and save the page. But that link is not removed and still there.
Any help is appreciated.
[WebMethod]
public void RemovePrivateLink(string privatelink)
{
UserService userservice = new UserService();
CurrentUserExtensions currentLoginUser = new CurrentUserExtensions();
var user = userservice.GetUserProfile(currentLoginUser.Signum);
if (user != null)
{
var userPage = (EmployeePage)user.Page.CreateWritableClone();
if (userPage != null)
{
LinkItem objLinkItem = new LinkItem();
objLinkItem.Href = privatelink;
//removing private link from the collection
userPage.PrivateLinks.Remove(objLinkItem);
var currentUser = HttpContext.Current.User;
//read value from web.config
System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
System.Configuration.KeyValueConfigurationElement setting = config.AppSettings.Settings["impersonateuser"];
var adminaccount = setting.Value;
//run as another user
System.Web.Security.MembershipUser muuser = System.Web.Security.Membership.Provider.GetUser(adminaccount, false);
System.Security.Principal.GenericIdentity identity = new System.Security.Principal.GenericIdentity(muuser.UserName, muuser.ProviderName);
GenericPrincipal principal = new GenericPrincipal(identity, System.Web.Security.Roles.GetRolesForUser(muuser.UserName));
HttpContext.Current.User = principal;
System.Threading.Thread.CurrentPrincipal = principal;
//save the page
EPiServer.DataFactory.Instance.Save(userPage, EPiServer.DataAccess.SaveAction.Publish);
}
}
}