Post by laco on Jan 11, 2011 7:52:51 GMT -6
Dear ladies and gentlemen,
i try to remove a member from an organization profile in a SharePoint 2010 programm through the following method:
private void RemoveUserProfile(long departmentRecordId, long userRecordId)
{
using (SPSite site = new SPSite(SiteUrl))
{
HttpContext tmpContext = HttpContext.Current;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSiteColl = new SPSite(site.ID))
{
using (SPWeb web = elevatedSiteColl.OpenWeb())
{
SPServiceContext serviceContext = SPServiceContext.GetContext(elevatedSiteColl);
HttpContext.Current = null;
OrganizationProfileManager organizationProfileManager = new OrganizationProfileManager(serviceContext);
OrganizationProfile organizationProfile = organizationProfileManager.GetOrganizationProfile(departmentRecordId);
organizationProfile.RemoveMember(userRecordId);
}
}
});
}
catch (Exception ex)
{
}
finally
{
HttpContext.Current = tmpContext;
}
}
}
I receive the following exception:
System.UnauthorizedAccessException
This coding approach is working well, when reading information from OrganizationProfile.
Do you know haw to remove an UserProfile from OrganizationProfile?
Thanks a lot for your help.
Laco
i try to remove a member from an organization profile in a SharePoint 2010 programm through the following method:
private void RemoveUserProfile(long departmentRecordId, long userRecordId)
{
using (SPSite site = new SPSite(SiteUrl))
{
HttpContext tmpContext = HttpContext.Current;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSiteColl = new SPSite(site.ID))
{
using (SPWeb web = elevatedSiteColl.OpenWeb())
{
SPServiceContext serviceContext = SPServiceContext.GetContext(elevatedSiteColl);
HttpContext.Current = null;
OrganizationProfileManager organizationProfileManager = new OrganizationProfileManager(serviceContext);
OrganizationProfile organizationProfile = organizationProfileManager.GetOrganizationProfile(departmentRecordId);
organizationProfile.RemoveMember(userRecordId);
}
}
});
}
catch (Exception ex)
{
}
finally
{
HttpContext.Current = tmpContext;
}
}
}
I receive the following exception:
System.UnauthorizedAccessException
This coding approach is working well, when reading information from OrganizationProfile.
Do you know haw to remove an UserProfile from OrganizationProfile?
Thanks a lot for your help.
Laco