sharepoint column default value settings not applied via content type

Problem:

Created Document library and associated custom content type with a site column containing default value. Say a numeric field with default value 1.

But when i upload document and select my custom content type, default value does not appear and is always blank.

Reason and solution:

Thanks to SWEE CHING’s article, that i found the solution. Reason was that my custom content type was not set as default content type. If you want your default values to appead pre-selected, you have to set your custom content type as default.

Hope it will help someone!

Advertisements

Fix Publishing Pages Page Layout URL error – Value does not fall within the expected range

While accessing publishing pages, you may encounter error –  “Value does
not fall within the expected range” . It happens due to one of the following reasons:
  • If the publishing layout URL of a publishing page contains an incorrect top level site URL.
  • If there is a problem with the Page Layout, or if the Page Layout is corrupted.
  • If a content database was moved or a content deployment job was run.
 
If you encounter this issue due to reason – 1 i.e. “If the publishing layout URL of a publishing page contains an incorrect top level site URL.”, you can fix it by executing following script.
 
It will fetch URL from Page Layout and verify if it is same as top level site URL. If not, it will change it to top level site URL and approve the page.
 
function AutoApprovePage($page)
{
    if($page.ListItem.ListItems.List.EnableModeration)
    {
        #Check to ensure page requires approval, and if so, approve it
        if ($page.ListItem[“Approval Status”] -eq 0)
        {
             write-host ” | Already approved:”, $page.Title -nonewline
        }
        else
        {
            $page.ListItem.File.Approve(“Page approved automatically by PowerShell script”)
             write-host ” | Approving:”, $page.Title -nonewline
        }
    }
    else
    {
         write-host ” | No approval required for: “, $page.Title
    }
}
 
CLEAR
$site = Get-SPSite -Identity “http://br203:50000”
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
Write-host “Processing SPWeb: “$pubWeb.Url
Write-host “Title: “$pubWeb.Title
       
$pagesList = $pubWeb.PagesList
$pageCount = 0
$badUrlCount = 0
$fixUrls = $true
foreach($page in $pagesList.Items)
{
    $curPubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($page)
    $pageLayout = $curPubPage.ListItem.File.Properties[“PublishingPageLayout”]
    $url = $pageLayout.SubString(0, $pageLayout.IndexOf(‘,’))
 
    $pageCount += 1
    if(!$url.StartsWith($site.RootWeb.Url,[System.StringComparison]::OrdinalIgnoreCase))
    {
        Write-Host ” |-Page:”$page.Title
        Write-Host ”   |-Layout:”$url -nonewline
        if($fixUrls)
        {
            #Construct the path to page. First, get the last index of / to getthe page name
            $pos = $url.LastIndexOf(‘/’)
            if($pos -ne -1)
            {
                $pubSPFile = $curPubPage.ListItem.File
                $rootWebUrl = $site.RootWeb.Url
                $pageName = $url.SubString($pos + 1)
                $newPageLayout = $rootWebUrl + “/_catalogs/masterpage/” + $pageName
                $pageLayoutFile = $site.RootWeb.GetFile($newPageLayout)
                if($pageLayoutFile.Exists)
                {
                    $checkedOutToUser =  $pubSPFile.CheckedOutByUser
                    if(($pubSPFile.CheckOutStatus -ne “None”) -and $undoCheckOut)
                    {
                        Write-host ”   |-File is Checked Out to: “$checkedOutToUser.Name”, but will be overridden” -foregroundcolor blue -nonewline
                        $pubSPFile.UndoCheckOut()
                    }
                    if($pubSPFile.CheckOutStatus -eq “None”)
                    {
                        $pubSPFile.CheckOut()
                        # Save the page layout as “url, pagename” (with a single space after url, this is important)
                        $propVal = $newPageLayout + “, ” + $pageName
                        $pubSPFile.Properties[“PublishingPageLayout”] = $propVal
                        $pubSPFile.Update()
                        $pubSPFile.CheckIn(“Fixed page layout url via auto-script.”,[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
                        AutoApprovePage($curPubPage)
                        $fixedUrlCount += 1
 
                        Write-Host ”   |-SetUrl:”$newPageLayout -nonewline
                        Write-Host ” (Fixed)” -foregroundcolor Green -nonewline
                    }
                    else
                    {
                        Write-host ”   |-Not fixed. File is Checked Out to: “$checkedOutToUser.Name $checkedOutToUser.Email -foregroundcolor blue -nonewline
                    }
                }
                else
                {
                    Write-Host ”   |-Not fixed. The page layout $pageName does not exist in the root web master page gallery.” -foregroundcolor blue -nonewline
                }
            }
        }
    }
}
 

Sharepoint Search Error/Search Service stuck at starting/Start or Stop a service using powershell

If ever you encounter a problem where search service is stuck at starting,or you recieve following message in event viewer related to search service, try steps given below:

The Execute method of job definition Microsoft.SharePoint.Search.Administration.SPSearchJobDefinition (ID ) threw an exception. More information is included below.
Retrieving the COM class factory for component with CLSID {} failed due to the following error: .
Event ID: 6398

First of all check if search service is started in services.msc

If still problem persists,
1) open windows powershell
2) Get Service InstanceID of search service application by entering following command:
Get-SPServiceInstance

​It will display all services with its ID

searchservice (1)

3) Copy ID of search service  and execute following command

Stop-SPServiceInstance -Identity <ID of search service>

 

4)Start search service using following command

Start-SPServiceInstance -Identity <ID of search service>

Content Organizer execution order

Content Organizer is used to organize your content automatically, based on custom-defined rules. However, these rules add new entity to the hierarchy of events that can be executed for the List items, and this execution order is not well documented. It’s important to understand the sequence to process documents accordingly.
For example, when the user uploads his CV to the library you want to add watermark by Workflow, update .docx metadata with event receiver and round document to “unprocessed” folder using content organizer. We have “DropOff Library” with WorkFlow, EventReceiver attached and with Content Rules. The default execution sequence will be the following:
  1. WorkFlow
  2. Event-Receiver
  3. Content Organizer Routing Rules
PS: Take into account that WF/EventReceiver sequence can be changed programmaticaly, using Sequence property of SPList.EventReceivers, but when you reconfigure Workflow it always gets the first order in execution
PPS: Content Organizer Routing Rules impersonates the Application Pool account, thus in might perform actions under “System Account” and your destination folder’s WorkFlow will not start.

Recover deleted site collection using powershell

  • Unfortunately, there is no user interface for restoring deleted site collections. Managing deleted site collections requires using PowerShell. SharePoint 2010 Service Pack 1 introduces 3 new PowerShell CmdLets for managing the Recycle Bin for site collections.

    • Get-SPDeletedSite
    • Restore-SPDeletedSite
    • Remove-SPDeletedSite

    The easiest way to get a list of all the deleted site collections is to just call Get-SPDeleteSite without any parameters. In the following example, for brevity, I have formatted the output as a table and filtered the columns displayed. In the second sample, I have added a wildcard filter to the command that can be used to easily filter sites based on relative paths.

    1178_5Once you have identified the site you want to restore, you call the Restore-SPDeletedSite. To restore one or more sites, it is easiest to just pipe the results from Get-SPDeletedSite. By default, the command will ask you to confirm the restore. To eliminate the confirmation, just add “Confirm:$true” to the end of the command.

    1178_6

    Ref: http://mssharepointtips.com/tip.asp?id=1178&page=3

     

Stringbuilder object returning result while using Append function

Problem

For appending content to stringbuilder object we use Append() as

$sb = New-Object -TypeName “System.Text.StringBuilder”;
 $sb.Append(“This is a demo”);
expected the result is
This is a demo
However the result is
                  Capacity                MaxCapacity                    Length
                  ——–                ———–                    ——
                        16                 2147483647                         11
This is a demo
Reason
Several of the methods on StringBuilder like Append IIRC, return the StringBuilder so you can call more StringBuilder methods. However the way PowerShell works is that it outputs all results (return values in the case of .NET method calls).
Solution
In this case, cast the result to [void] to ignore the return value e.g.:
[void]$sb.Append(“This is a demo”)