Thursday, December 20, 2012

An exception occurred when trying to issue security token: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs..

check your web.config files

1) Central admin,

2) C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\SecurityToken

3) Your web app

in my case some wiered content added to my config file. please see below which is highlated with yellow color.

Under RoleManager section
<add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, &#xD;&#xA;Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

Under Membership section

<membership defaultProvider="i" userIsOnlineTimeWindow="15" hashAlgorithmType="">
        <clear />

        <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, &#xD;&#xA;Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />

remove unwanted data and iisreset.

it worked for me.

Thursday, November 1, 2012

Get all SharePoint Users and Groups using PowerShell Script

# it shows username, emailid, group names which user belogns to 
# domainname\surya,, group1; group2; group3;

copy below code to notepad file and save it as "users_groups.ps1" file.
Run the below script using SharePoint management shell. once you run the script you can see the .csv file will be created where you are running this file. for ex: if you are running this script d:\surya, you can the log file in the same location.

$site = New-Object Microsoft.SharePoint.SPSite("http://spdev6:8003")
$web = $site.openweb("")
 Write-Host $web.url
$i = 1
$timestamp = get-date -format "yyyyMMdd_hhmmtt"
$filenameStart = "UsersLog"
$logfile = ("{0}{1}.txt" -f $filenamestart, $timestamp)

$header = "UserName,Email, Group"
$header | out-file -FilePath $logfile

      write-host $i   "UserName:"  $user  "Groups:" $user.groups

            #Write-Host "siteusers" $web.siteusers["ajay.thomas"]
      $semicolon = ";" 
      Write-Host $semicolon
      foreach ($user in $web.siteusers)
      #[string]$UserName= $user.ToString()
      #if ($UserName.ToUpper().StartsWith("surya"))
            foreach ($grp in $user.groups)
                  $str = $str +  $ + $semicolon
                  #Write-host   $  ";"
            #Write-Host $i  $user  "," $  ","   $str
            Write-Host $user  "," $ ","  $str "," $user.ID
# $
            $msg = ("{0},{1},{2} " -f $user, $, $str)
            $msg | out-file -FilePath $logfile  -append
            $str= $null
       #Write-Host $i++

Friday, August 3, 2012

SharePoint 2010: Custom Rss Feed for Document Library

Here is the good post for custom Rss Feed. It worked for me.

 If you are working for document library replace “LinkTitle” with Title as shown below code.

foreach (SPListItem item in items)
              AddTag("title", item["Title"].ToString(), sb);
              //AddTag("link", list.RootFolder.Url + "/DispForm.aspx?ID=" + item.ID, sb);

             // AddTag("link", "http://site/News/default.aspx?itemid=" + item.ID, sb);

             AddTag("link", "http://site/news/default.aspx?itemid=" + item.ID, sb);
              //AddTag("link", listurl  + item.ID, sb);
              foreach (string viewField in view.ViewFields)

                  if (viewField != "Title")
                  //if (viewField != "LinkTitle")
                      AddTag(viewField.Replace("_x0020_", " "),item.GetFormattedValue(viewField), sb);

Wednesday, July 25, 2012

SharePoint 2010 : List "Order field" is hidden

just run the below script and "order" field will be visible in the list.

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
$WebAppUrl = "http://site/"

$site=new-object Microsoft.SharePoint.SPSite($WebAppUrl
foreach ($web in $site.AllWebs) 
  Write-Host      $web.Url
  for ($i = 0; $i -lt $webLists.Count; $i++)
     $spList = $weg.Lists[$i] #;   # ... }
      #foreach ($spList in $web.Lists) 
      # { 
            #if ($spList.BaseTemplate -eq "GenericList" -or $spList.BaseTemplate -eq  "DocumentLibrary" )
            if ($spList.BaseTemplate -eq "GenericList")
                  # Write-Host  $spList.title
                  if ($web.Url -eq "http://site")
                     #Write-Host  $spList.title
                      $orderField = $spList.Fields["Order"]
                        $type = $orderField.GetType()
                        $mi = $type.GetMethod("SetFieldBoolValue", [reflection.bindingflags]"nonpublic, instance")
                        $parameters = "CanToggleHidden", $true
                        $mi.Invoke($orderField, $parameters)
                        if($orderField.Hidden -eq $true)
                              Write-Host  "Surya" $spList.Title
                              #if($spList.title -ne "Relationships List"  -or $spList.title -ne "Web Site Menu - First Level"   -or $spList.title -ne "Variation Labels" -or $spList.title -ne "TaxonomyHiddenList" -or $spList.title  -ne "Suggested Content Browser Locations" -or $spList.title -ne "Reusable Content" -or  $spList.title -ne "Reporting Metadata" -or $spList.title -ne "Notification List" -or  $spList.title -ne "Quick Deploy Items" -or $spList.title -ne "QuickLinksList")
                                    $orderField.Hidden = $false



SharePoint: Master Page is not updating with feature after deployment

I noticed below points while working with master page

If master page is not customized, I mean if it is not modified by SharePoint designer or any other tool

  2nd time when I am done with modifications in my feature code, I am updating a master page feature    using below powershell script

update-spsolution -identity MasterPages.wsp  -literalpath C:\Pulipati\.MasterPages.wsp  -  gacdeployment
a.    My Master page is updating properly however it is not creating a version and it is not updating the modified date as well when I run above command.  But when I open a master page I see latest code.

If master page is customized, I mean if it is modified by SharePoint designer or any other tool

  If I run powershell command it is not updating my master page. So I followed this Post and successfully updated.

<Module Name="PGCMasterPageModule" List="116" Url="_catalogs/masterpage">
  <File Path="xxxMasterPageModule\CustomMaster.master" Url="CustomMaster.master"  IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary" />

IgnoreIfAlreadyExists="TRUE": always make this TRUE it will not throw any error when you deploy second time.

using System.IO;

  public override void FeatureActivated(SPFeatureReceiverProperties properties)
            //if you want to debug just enable this code
            // System.Diagnostics.Debugger.Break();

            SPSite currentSite = (SPSite)properties.Feature.Parent;
            SPWeb oCurrentWeb = currentSite.RootWeb;

           oCurrentWeb.MasterUrl = oCurrentWeb.ServerRelativeUrl +    "/_catalogs/masterpage/CustomMaster.master";
            oCurrentWeb.CustomMasterUrl = oCurrentWeb.ServerRelativeUrl + "/_catalogs/masterpage/CustomMaster.master";

//below code executes only when the file is customized (for ex: if u modify with sharepoint designer) 

       if (oFile.CustomizedPageStatus == SPCustomizedPageStatus.Customized)
            // Here we are trying to overwrite the default.master  
            SPFile oFile = oCurrentWeb.GetFile("_catalogs/masterpage/CustomMaster.master");
            SPFolder oFolder = oCurrentWeb.Lists["Master Page Gallery"].RootFolder;
            // Check In the file  
            if (oFile.CheckOutType != SPFile.SPCheckOutType.None)
                oFile.CheckIn("auto checkin");
            // Check Out the file for edit.  
            string directory = properties.Definition.RootDirectory; // it returns 14 hive feature path
            directory += @"\PGCMasterPageModule"// my feature module name as shown in picture

            // Get the master page name from the feature properties as defined in the elements.xml 
            //  SPFeatureProperty oPropertyName = properties.Feature.Properties["CustomMaster.master"];

            // Get the file names from the specified directory matching the feature property value. 
            string[] templates = Directory.GetFiles(directory, "CustomMaster.master", System.IO.SearchOption.TopDirectoryOnly);
            // templates should have all the matching file names. In this instance it whould be only one file name. 
            string MasterPageFile = templates[0];
            FileInfo fileInfo = new FileInfo(MasterPageFile);
            byte[] byteArr = System.IO.File.ReadAllBytes(MasterPageFile);
            oFolder.Files.Add(fileInfo.Name, byteArr, true);
            oFile.CheckIn("Check in");



Tuesday, July 24, 2012

SharePoint 2010: Powershell commands

Powershell Commands

Add-SPSolution D:\Wsps\SampleSolution.wsp

Install-SPSolution –Identity SampleSolution.wsp -GACDeployment
Install-SPSolution –Identity SampleSolution.wsp -webapplication http://site -gacdeployment -force

Update-SPSolution –Identity SampleSolution.wsp –LiteralPath d:\test.wsp –GACDeployment

uninstall-spsolution -identity SampleSolution.wsp -webapplication http://site -confirm:$false

remove-spsolution -identity SampleSolution.wsp -confirm:$false

Backup-spsite –identity http://sitename  -path D:\backup\surya\9019.bak

Restore-SPSite –identity http://sitename  -path D:\backup\surya\9019.bak –force

Mount-SPContentDatabase "MyDatabase" -DatabaseServer "MyServer" -WebApplication http://sitename

Restore-SPSite -Identity "http://spdev5:8002/"  -Path "site_05312013.bak" -DatabaseName "sitedb"  -force -verbose

#Export SharePoint List
Export-SPWeb  "http://spdev5:8005" -path "D:\\Development\surya\ResourceLibrary.cmp" -ItemUrl Resource%20Library -IncludeVersions All

#Import SharePoint List
Import-SPWeb -Identity http://spdev5:8003 -path "D:\Development\surya\ResourceLibrary.cmp"

STSADM Commands

stsadm -o provisionservice -action start -servicetype spwebservice
stsadm -o backup -url  http://sitename  filename C:\Pulipati\testbackup.bak
stsadm.exe -o import -url http://sitename -filename C:\ -includeusersecurity

stsadm -o provisionservice -action start -servicetype Microsoft.SharePoint.Administration.SPWebService -servicename WSS_Administration

Not enough information to determine a list for module. Assuming no list for this module

Its throwing error when you forgot to mention Url.  that’s what I noticed.

IgnoreIfAlreadyExists : True : It will not throw any error if already exists.
IgnoreIfAlreadyExists : False : It throws an error if already exists.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <Module Name="MyStyles" Url="Style Library" >
    <File Path="MyStyles\Sample.txt" Url="Sample.txt"  Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
    <File Path="MyStyles\NewFolder1\Style.css" Url="NewFolder1/Style.css"  Type="GhostableInLibrary"   IgnoreIfAlreadyExists="TRUE"/>