Pages

Monday, 23 January 2017

SharePoint Framework Developer Preview


SharePoint Framework developer preview is out...... https://dev.office.com/sharepoint 

Only available for Office365 and SharePoint 2016

Patterns and Practices for SharePoint: https://dev.office.com/patterns-and-practices 

Wednesday, 21 January 2015

Useful PowerShell Commands for SharePoint 2010

  • To get the current verion of SharePoint Installed:
     get-spfarm | select BuildVersion
 
  • Export a list from SharePoint 2010
    
    Export-SPWeb "http://sitecollection/subsite/subsubsite/subsubsubsite/" -itemurl "/subsite/subsubsite/subsubsubsite/Lists/myList" -path "e:\backups\myList.cmp"
    
    

Getting Started with Team Foundation Service TFS) with Visual Sudio 2010 Developer Edition



Easy to follow articles here:

http://blogs.msdn.com/b/visualstudioalm/archive/2011/12/07/connect-visual-studio-2010-to-your-tfs-preview-account.aspx

https://tfs.visualstudio.com/en-us/learn/code/connect-vs/


Using PowerShell to set a custom SharePoint 404 Error Page

Using PowerShell to set a custom SharePoint Error Page

You can define a custom error page for SharePoint (see Jingmei Li's Blog) for instructions.
Here are the PowerShell caommands I used instead of having to compile a console app (step 5 in Jingmei's blog).
PS C:\> [System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
PS C:\> $webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("http://www.wssdemo.com")
PS C:\> $webapp.FileNotFoundPage = "wssdemo404.html"
PS C:\> $webapp.Update()
Now try a page that doesn't exists like http://www.wssdemo.com/pages/deletedpage.aspx

Monday, 10 February 2014

The end of an era......... InfoPath comes to an end

"In an effort to streamline our investments and deliver a more integrated Office forms user experience, we’re retiring InfoPath and investing in new forms technology across SharePoint, Access, and Word. This means that InfoPath 2013 is the last release of the desktop client, and InfoPath Forms Services in SharePoint Server 2013 is the last release of InfoPath Forms Services. The InfoPath Forms Services technology within Office 365 will be maintained and it will function until further notice."

http://blogs.office.com/2014/01/31/update-on-infopath-and-sharepoint-forms/ 

Monday, 6 January 2014

How to get the selected Item from a webpart and pass it as a parameter in a query string

For this example we have 2 lists
1: Person - Fields: Document title (which is the name)
2: Details - Fields: Person (lookup to Document Title in Person List) and Phone No (text)

We have a page with both list viewer web parts and both are connected with filter values being passed from "Person" to "Details"



when you select an ID from the Person web part the details are populated, however, if you select the 2nd item from Person web part and would like to add a new number to under details you have to select the Person from the drop down. This is not a solution as it can get very labor intensive as the number of "persons" increase.


















An alternate approach would be to append the ID of the selected "Person" (which you can get from the selected item) to the query string, read this value and populate this value by default.

Here is the javascript to change the display text instead of default text "add new item"

<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push('ChangeText');

function ChangeText()
{
var ttnA = document.getElementsByTagName('a');
var ttnCounter = 0;
for (var j=0; j<ttnA.length; j++)
{

  if (ttnA[j].id == 'idHomePageNewItem')
  {
  ttnCounter++;
  if(ttnCounter ==1) /* This is the webpart sequence, if it was the 3rd web part on the page the id would be 2 */
{

var selectedImg$ = $('img[alt^="Selected"]');
var elemID = selectedImg$.closest('tr').attr('iid').split(',')[1];
var linkText = selectedImg$.closest('tr').find('div#' + elemID).find('a').text();
//alert(linkText);
                var linkTextReplaced = linkText.replace("DEVDOMAIN\\","");

                $(ttnA[j]).attr("href","javascript:NewItem2(event,'http://dev/marketing/Lists/Details/NewForm.aspx?RootFolder=&IsDlg=1&Web=f939c7f8%2Dd6e0%2D4046%2D854d%2D070b31bce0cf&UserID="  + linkTextReplaced + "');");
       
 $(ttnA[j]).removeAttr("onclick");
                ttnA[j].innerHTML='Click to add a new phone number for DEVDOMAIN\\' + linkTextReplaced
        
       }
     }
   }
}</script>

PowerShell script to copy a SharePoint Document Library to a Local Path

PowerShell script to copy a SharePoint Document Library to a Local Path

I cannot take credit for this awesome script, it was done by JBMurphy.com

Function JBM-SharePoint-CopyDocumentLibraryLocal {
PARAM([Parameter(Mandatory=$true)]$SiteURL,
    [Parameter(Mandatory=$true)]$DocumentLibrary,
    [Parameter(Mandatory=$true)]$Destination)
$spWeb = Get-SPWeb -Identity http://$SiteURL
$list = $spWeb.Lists[$DocumentLibrary]
foreach ($listItem in $list.Items)
{
    $DestinationPath = $listItem.Url.replace("$DocumentLibrary","$Destination").Replace("/","\")
    write-host "Downloading $($listItem.Name) -> $DestinationPath"
    if (!(Test-Path -path $(Split-Path $DestinationPath -parent)))
    {
        write-host "Createing $(Split-Path $DestinationPath -parent)"
        $dest = New-Item $(Split-Path $DestinationPath -parent) -type directory
    }
    $binary=$spWeb.GetFile($listItem.Url).OpenBinary()
    $stream = New-Object System.IO.FileStream($DestinationPath), Create
    $writer = New-Object System.IO.BinaryWriter($stream)
    $writer.write($binary)
    $writer.Close()
}
$spWeb.Dispose()
Rererence: http://www.jbmurphy.com/2012/04/25/powershell-script-to-copy-a-sharepoint-document-library-to-a-local-path/ 

The site is not valid. The 'Pages' document library is missing.



The site is not valid. The 'Pages' document library is missing.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.SharePoint.Publishing.InvalidPublishingWebException: The site is not valid. The 'Pages' document library is missing.


How to fix the problem?
To fix the issue it is required to update the value of the __PagesListId property value to match the ID of the Pages library.

This can be done (e.g.) through the following Powershell script:
$web = get-spweb http://site-collection/path-to-affected-site
$correctId = $web.Lists["Pages"].ID
$web.AllProperties["__PagesListId"] = $correctId.ToString()
$web.Update()

Reference: http://blogs.technet.com/b/stefan_gossner/archive/2011/09/15/common-error-the-site-is-not-valid-the-pages-document-library-is-missing-error.aspx

Programmatically view all file versions in a list

A very nice article by Anita about getting document versions:

SPDocumentLibrary sharedDocs = SPContext.Current.Web.Lists['Shared Documents'as SPDocumentLibrary;
resultBox.Text = string.Empty;
foreach (SPListItem doc in sharedDocs.Items)
{
     SPListItemVersionCollection coll = doc.Versions;
     resultBox.Text += 'Versions of  ' + doc.Name + Environment.NewLine;
     foreach (SPListItemVersion version in coll)
     {
          resultBox.Text += 'VersionLabel: ' + version.VersionLabel + ' IsCurrentVersion: ' + version.IsCurrentVersion + Environment.NewLine;
     }
}

And the result:


http://www.itidea.nl/index.php/documents-and-versioning

Restoring the User Profile Service application on a different server in a different SharePoint Farm on the same Domain - SharePoint 2010

It has been a while since my last post, I have been very busy in my new role. Thought why not start by addressing the User Profile Service application (UPA). 

As developers and administrators we tend to stay away from UPA, and to be fair, it is a slightly complicated service application to migrate.


Background:


We have a PROD-STANDBY used as an interim step and all the new features and enhancements are done here and then a DNS switch is applied. This way our down time is reduced, our typical downtime has been around 5 mins mainly for the DNS to propagate.


Farm Configuration:
PROD: 1 X WFE/APP + 1 X DB Server
PROD_STANDBY: 1 X WFE/APP + 1 X DB Server

Approach:

In order to keep the user profile information in sync, we decided to re-create the user profile service application but had a backup of the UPA databases (Profile DB, Social DB, from the PROD server.

As per the Technet article (http://technet.microsoft.com/en-us/library/ff681014(v=office.14).aspx#resetSync) we had a few issues regarding user profiles being marked for deletion so had to take alternate approaches.



Create the UPS Service Application
  1. Application Management, Manage service applications
  2. From the Ribbon, click New, followed by User Profile Service Application
  1. Give it a sensible name
  2. Create a new App Pool (SharePoint Web Services Default) and use the DOMAIN\SPServices managed account
  1. Accept the defaults for the three Databases
  2. Select the machine in the farm running FIM (well it’s not running yet but this UI is crap it just lists servers in the farm)
  1. Enter the URL of the mysite host (http://my.sharepoint.com) amazingly this step actually validates the target site collection!
  1. Select your managed path and site naming scheme.
  2. Click Create, and wait while the Service Application, Service Connection and Databases are created.


[UPDATE 11/09/2010] if the NetBIOS name of the name is different from the fully qualified name (FQDN) you will also need to configure the Service Application to support this. To enable the Service Application to support NetBIOS name resolution, run the following Windows PowerShell:
1
$upsa = Get-SPServiceApplication –Id <GUID of User Profile Service Application> $upsa.NetBIOSDomainNamesEnabled=1 $upsa.Update()  # To get the GUID of the User Profile Service Application run Get-SPServiceApplication.




Reset profile synchronization
The User Profile Synchronization database serves as a staging area for user profile information. User Profile information that is stored in the profile store and synchronization database is consumed by the User Profile service. By following these steps, you can safely reset a User Profile Synchronization database without losing information in the profile store.

To reset profile synchronization by using Windows PowerShell
  1. Verify that you meet the following minimum requirements:
    • See Add-SPShellAdmin.
    • You must be a member of the Farm Administrators group on the computer that is running the SharePoint Central Administration Web site.
    • The farm account, which is created during the SharePoint farm setup, must also be a Local Administrator on the server where the User Profile Synchronization service is deployed.
      This is required to start the User Profile Synchronization service. After the User Profile Synchronization service is started you can remove the farm account from the Administrators group.
  1. As a precaution, back up the User Profile service application. For more information, see Back up a service application in SharePoint Server 2010.
  2. If you are using the My Site cleanup timer job, you must disable it before you reset the synchronization database. Otherwise, the job will delete all user profiles and My Sites from the farm. For information about this timer job, see the Timer job reference (SharePoint Server 2010). For information about the Windows PowerShell cmdlets that you use to enable and disable this timer job, see Timer jobs cmdlets (SharePoint Server 2010).
  3. Disable the User Profile Incremental Synchronization timer job:
    1. On the SharePoint Central Administration Web site, click Monitoring.
    1. Click Review job definitions.
    1. Click User Profile Service Application Name-User Profile Incremental Synchronization.
      Where 
      User Profile Service Application Name is the name of the User Profile service application.
    2. Click Disable.
  1. On the Start menu, click All Programs.
  2. Click Microsoft SharePoint 2010 Products.
  1. Right-click SharePoint 2010 Management Shell and then click Run as administrator.
  1. In the User Account Control dialog box, click Yes.
  1. At the Windows PowerShell command prompt, type the following command to stop the SharePoint 2010 Timer service:
    net stop sptimerv4
  1. Copy the following code and paste it into a text editor, such as Notepad:
    $syncdb=Get-SPDatabase <SyncDBGUID>
    $syncdb.Unprovision()
    $syncdb.Status='Offline'
    $upa=Get-SPServiceApplication <UPSAppGUID>
    $upa.ResetSynchronizationMachine()
    $upa.ResetSynchronizationDatabase()
    $syncdb.Provision()
  1. Replace the following placeholders with values where:
    • <SyncDBGUID> is the GUID of the synchronization database.
    • <UPSAppGUID> is the GUID of the User Profile Service application.
      For more information, see 
      Get-SPDatabase.
  1. Save the file as an ANSI-encoded text file and name the file ResetSyncDB.ps1.
  1. At the Windows PowerShell change to the directory where you saved the file.
  1. Type the following command:
    ./ResetSyncDB.ps1
  1. Using SQL Server Management Studio, create a login in SQL Server for the User Profile Synchronization service account (that is, the farm account). Then, in the Sync database, create a database user that maps to the login and grant it access to the db_owner database role. For more information, see How to: Create a SQL Server Login (http://go.microsoft.com/fwlink/p/?LinkId=211993), How to: Create a Database User(http://go.microsoft.com/fwlink/p/?LinkId=211994), and Database-Level Roles (http://go.microsoft.com/fwlink/p/?LinkId=211995).
  1. At the Windows PowerShell command prompt, type the following command to start the SharePoint 2010 Timer service:
    net start sptimerv4
  1. Start the Profile Synchronization service. For more information, see the Start the User Profile Synchronization service section of the "Configure profile synchronization" topic.
  1. Reset IIS. For more information about how to reset IIS, see the Reset IIS section of the "Configure profile synchronization" topic.
  2. Create connections to the data sources. For more information, see Restore a service application (Search Server 2010).
  3. If you do not intend to use the My Site cleanup timer job, run profile synchronization. For more information about how to run profile synchronization, see Start profile synchronization manually (SharePoint Server 2010). If you intend to enable the My Site cleanup timer job, complete these additional steps before you enable the job:
    1. Run two full profile synchronizations.
    1. After the second profile synchronization completes, on the Central Administration Web site, in the Application Management section, click Manage service applications.
    1. Click the User Profile service application name, and then click Manage.
    1. On the Manage Profile Service page, in the People section, click Manage User Profiles.
    1. Next to View, select Profiles Missing from Import.
    2. In the Find Profiles box, type the domain for the profiles and then click Find.
    3. For each profile that is returned, check the originating directory service, such as Active Directory, for the status of that profile. If the status of any of the returned profiles in the directory is not disabled or is not deleted, do not enable the My Site cleanup timer job. Contact Microsoft support for more assistance. Otherwise, enable the My Site cleanup timer job. For information about the Windows PowerShell cmdlets that you use to enable and disable this timer job, see Timer jobs cmdlets (SharePoint Server 2010).
  1. Enable the User Profile Incremental Synchronization timer job:
    1. On the SharePoint Central Administration Web site, click Monitoring.
    2. Click Review Job Definitions.
    3. Click User Profile Service Application Name-User Profile Incremental Synchronization.
      Where 
      User Profile Service Application Name is the name of the User Profile service application.
    4. Click Enable.

Notes:

After you have restored and you run the user profile sync jobs, you notice the sync jobs are running fine and you get excited that everything is working well.

Don't congratulate yourself too quickly, you may notice the next day that all user profiles have been deleted..........

I faced this problem (might not happen to you), here is what I had to do:

Run this SQL query against your user profile database:

Select * from userprofile_full (nolock) where bDeleted = 1

In my case I just updated bDeleted to 0

I acknowledge that modification of SQL database for SharePoint is not recomemded but after 3 days of pain staking exercise I did not see another way out. The profile Sync has been running fine for about 3 months now. This is not my recommendation, it is just what I did to make it work.

  • Run the Incremental Synchronization about 5 times and if the bDeleted field in the database is still marked at 1 run the following update command (*ensure you have database backups):


update dbo.UserProfile_Full set bDeleted=0 where bDeleted =1



*********** References **************

Also refer to this technet article: http://technet.microsoft.com/en-us/library/ff681014.aspx#resetSync


"Stuck on Starting"

How to configure user profile synchronisation service application:


Restore a UPA MSDN: