Sunday, November 23, 2014

Sharepoint Custom Claims provider - Fill Resolve method implementation.


In order to have the fillresolve methods to be triggered, you need to have the property SupportsResolve to true.

We will have 2 overload methods of fillResolve in your custom claims provider. You need to implement both of these methods.

protected override void FillResolve(Uri context, string[] entityTypes, string resolveInput, List<Microsoft.SharePoint.WebControls.PickerEntity> resolved) - This method will be called when you enter name in the text box and click resolve.

and

protected override void FillResolve(Uri context, string[] entityTypes, SPClaim resolveInput, List<Microsoft.SharePoint.WebControls.PickerEntity> resolved) - This method will be called when you enter name in the people picker and click add, it will call fillresolve as it needs to resolve the name as soon as we have an entry in textbox.


You need to implement the Picker entity; Use SPClaim constructor instead of CreateClaim constructor.

private PickerEntity GetPickerEntity(string ClaimValue, string type)
{
PickerEntity pe = CreatePickerEntity();
 
/* in my case, emailaddress is the identity claim. Make sure that the last parameter TrustedProvider is correct, otherwise name resolution will not be correct. */

pe.Claim = new SPClaim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", ClaimValue, ClaimValueType, SPOriginalIssuers.Format(SPOriginalIssuerType.TrustedProvider, "Trusted User"));  

pe.EntityData[PeopleEditorEntityDataKeys.AccountName] = ClaimValue;
pe.EntityData[PeopleEditorEntityDataKeys.Email] = ClaimValue;
pe.DisplayText = ClaimValue;
pe.EntityData[PeopleEditorEntityDataKeys.DisplayName] = ClaimValue;
pe.EntityType = SPClaimEntityTypes.User;
pe.IsResolved = true;
return pe;
}

More Information

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.claims.spclaim.spclaim.aspx

http://blogs.technet.com/b/speschka/archive/2010/05/25/replacing-the-out-of-box-name-resolution-in-sharepoint-2010-part-2.aspx

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.claims.spclaimprovider.fillsearch.aspx

Powershell- Add or Remove User from Sharepoint Group

The below sample adds / removes list of user from a sample file.

Sample File: C:\Scripts\user.txt


domainname\user1
domainname\user2
domainname\user3


ADD USERS

$site = new-object Microsoft.SharePoint.SPSite("http://siteurl")
$web = $site.OpenWeb()

$group=$web.Groups["GroupName"]

$users=Get-Content C:\Scripts\user.txt

foreach ($user in $users) {

   write-host "adding user " $user  "to group "  $group
   $temp = $web.EnsureUser($user)
   $group.AddUser($temp)
  
}



REMOVE USERS

$site = new-object Microsoft.SharePoint.SPSite("http://siteurl")
$web = $site.OpenWeb()

$group=$web.Groups["GroupName"]

$users=Get-Content C:\Scripts\user.txt



foreach ($user in $users) {

   write-host "removing  user " $user  " from group "  $group
   $temp = $web.EnsureUser($user)
   $group.RemoveUser($temp)
  

Sunday, November 16, 2014

How to stop Silverlight videos via Javascript

I was exploring on how to stop the video that is being played within silverlight via javascript. I couldn't find any straight cut sample on stop function. However, updating or resetting source seems to do the trick !!!

You have to set id for your object tag

<object id=''videoID" ......>

Then I used jquery to set the source

$('#videoID').get(0).source = "<your xap file location>"

You can achieve the same using javascript as below

var videoElement=document.getElementById("videoID");
videoElement.source="<your xap file location>"