Saturday, January 23, 2021

Missing features in a SharePoint

 Run the Test-spcontentDatabase command against the content DB to get the list

use this SharePoint Feature Administration and Clean Up Tool to identify and remove them



You can uninstall it using stsadm as for SharePoint 2010


stsadm -o uninstallfeature -name {MyFeatureName}

where {MyFeatureName} is the name of the folder the feature sits in the FEATURES folder in the SharePoint hive.


stsadm -o uninstallfeature -id {GUID}

How to remove hyperlink from SharePoint calendar web part event?

 ExecuteOrDelayUntilScriptLoaded(removeCalendarLinks, "sp.ui.applicationpages.calendar.js");


// call the below function or append to onsuccess handler

function removeCalendarLinks() {

 $(document).ready(function() {

    $('div.ms-acal-mdiv a').each(function() {

        $(this).attr('onclick', 'return false;')

        $(this).attr('href', '#');

    });

 });

}

How can I navigate to the mysite of someone else?

 In this article, how to find the site

You can browse MySite in couple of ways but keep in mind you will get only the information which User Shared or common information from profile.


you can search the User from people Search or go to your own newsfeed check for organization chart.

Once you click on the user's profile link it will bring the user's profile page.

on this page left handside, you will see the information which user allow to see other.

If you have permision on user's one drive then you will see document link.otherwise you will see the About user and People.

Friday, January 8, 2021

get user profile property value when privacy for property set to “Private” (only me)

 RunWithElevatedPrivileges required because only under elevated code .
we can run that WindowsIdentity.GetCurrent() returns application pool account


SPSecurity.RunWithElevatedPrivileges(delegate

{

    var context = HttpContext.Current;

    HttpContext.Current = new HttpContext(new HttpRequest(string.Empty, SPContext.Current.Site.Url, string.Empty), new HttpResponse(new StringWriter()));

    HttpContext.Current.User = new GenericPrincipal(WindowsIdentity.GetCurrent(), new string[0]);

    var manager = new UserProfileManager(SPServiceContext.GetContext(HttpContext.Current));

    var profile = manager.GetUserProfile(@"domain\name");

    var value = profile["my_property"].Value;

    HttpContext.Current = context;

});  

change the user profile property value for all users via PowerShell?

 Add-PSSnapin Microsoft.SharePoint.PowerShell


$site=Get-SPSite "https://site.drizzleinfotech.in"

$serviceContext = Get-SPServiceContext $site;            


$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);            

$userProfile = $upm.GetUserProfile("raghur@drizzleinfotech.in");


foreach($userProfile in $upm)

{

  $userProfile["PropertyName"].Value = "Test Value";   

  $userProfile.Commit()

}

Thursday, January 7, 2021

Get all sites and all sub sites using SharePoint online REST API?

 Created Add-in on SharePoint instance with following permission xml

<AppPermissionRequests>

        <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl"/>

        <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/>

</AppPermissionRequests>


Used below API to get all sites and subsites

http://devprasad007-admin.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site' &rowlimit=100


https://<site_name>.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site 

Path:"https://<site_name>.sharepoint.com/*"'&rowlimit=500 

Getting ALL users from SharePoint online tenant and set userprofile property via Powershell

Getting all user profiles within SharePoint tenant using SharePoint Online CSOM API

  • retrieve all the users in tenant (Get-MsolUser cmdlet)
  • iterate users and utilize SharePoint User Profiles CSOM API to retrieve user profile

function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password)
{
   $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
   $context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password
   return $context
}


function Get-SPOCredentials([string]$UserName,[string]$Password)
{
   $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
   return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}



function Print-UserProfileInfo([Microsoft.SharePoint.Client.UserProfiles.PeopleManager]$PeopleManager,[string]$AccountName){
   $ctx = $PeopleManager.Context
   $accountName = "i:0#.f|membership|" + $AccountName  #claim format  
   $userProfile = $PeopleManager.GetPropertiesFor($AccountName)
   $ctx.Load($userProfile)
   $ctx.ExecuteQuery()
   Write-Host $userProfile.PersonalUrl
}

How do I pass user credentials SharePoint Online?

  SharePoint 2013 Client Object Model now has a class called SharePointOnlineCredentials

using (ClientContext Ctx = new ClientContext("http://devprasad007-admin.sharepoint.com"))  

{  

    SecureString passWord = new SecureString();

    Ctx.Credentials = new SharePointOnlineCredentials("ramp@devprasad007.onmicrosoft.com", passWord);

    Web web = Ctx.Web;

    Ctx.Load(web);

    Ctx.ExecuteQuery();

    Console.WriteLine(web.Title);

    Console.ReadLine();

Change permissions of a SharePoint list using JavaScript?

Break role inheritance for a List object and grant Full Control permissions for a current user



 var listTitle = 'Documents';

var spCtx = SP.ClientContext.get_current();

var list = spCtx.get_web().get_lists().getByTitle(listTitle);   


spCtx.load(list,'HasUniqueRoleAssignments'); 

spCtx.executeQueryAsync(

   function(){

      var hasUniqueAssgns = list.get_hasUniqueRoleAssignments();

      if(!hasUniqueAssgns) {

         list.breakRoleInheritance(false, true);

         spCtx.executeQueryAsync(

            function(){

                console.log('Success');

            }, 

            function(sender,args){

               console.log(args.get_message());    

            }

         );

      }

   }, 

   function(sender,args){

      console.log(args.get_message());    

   }

);

Web.GetFileByServerRelativeUrl throws “Value does not fall within expected range”?

 SP Online site stored in Documents, When we trying to adding/retrieving documents but in the delete flow If you get an error during retrieval of a File object.


var relativeUrl = "/sites/documentsite/Documents/images.jpg";
we have to specific or construct the full URL.