SharePoint Developer Support Team Blog

The Official blog of the SharePoint Developer Support Team

September, 2013

  • HOW TO: Change master page of a personal site in SharePoint 2013

    This post is a contribution from Pavan Kumar, an engineer with the SharePoint Developer Support team.

    As in SharePoint 2007 and 2010, one of the ways to achieve this is to use FeatureStapling.  Below are the steps to be followed to get this working.

    Create a SharePoint 2013 Empty project in Visual Studio 2012 and give it a name (e.g., ChangeMySiteMaster).

    image

    Provide your MySite Host URL and choose to deploy this as a farm solution.

    image

    Add a new Module from Visual Studio 2012 SharePoint item templates to the project.

    image

    By default, MySites use mysite15.master as its default master page.  This can be found under 15\TEMPLATE\FEATURES\MySiteMaster\mysite15.master.  Copy this file and add it to the project you created.  Rename it to CustomMySite.master and modify this file per your needs.

    Delete Sample.txt available in the Module and edit Elements.xml file such that it looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Module Name="MasterPage" List="116" Url="_catalogs/masterpage" Path="MasterPage" RootWebOnly="TRUE">
        <File Url="CustomMySite.master" Type="GhostableInLibrary"/>
      </Module>
    </Elements>

    Add a new feature to the project and add a feature event receiver to it.  Ensure that module is added to the feature.

    image

    image

    Add below code in FeatureActivated event of EventReceiver.cs.

    image

    Add below code in FeatureDeactivating event of EventReceiver.cs.

    image

    Create another farm level feature.  Name it as MySiteFarmStapler.  Add a new empty element to the project and name it as ML_ApplyCustomMasterPageStapler.  Add the following markup to the XML.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <FeatureSiteTemplateAssociation Id=<GUID from EventReceiver.cs>" TemplateName="SPSPERS" />
    </Elements>

    Add the module to Stapler feature.

    image

    Save all the files and deploy.  Login to your personal site and activate the feature from Site collection features.  Personal sites created henceforth will have the new master page applied to it.

  • HOW TO: Publish a LightSwitch App (high-trust) to SharePoint On-Premises environment

    This post is a contribution from Raghavendra B Nanjaiah, an engineer with the SharePoint Developer Support team.

    Just wanted to publish this post provided the steps to publish a LightSwitch App to SharePoint On-Premises environment.  Hope you will find this useful.

    Section 1: Create issuer ID (same as high-trust app)

    1. Check if any previously registered SPTrustedSecurityTokenIssue exists.  If there’s a malfunctioning one and if –IsTrustBroker switch was used, it means the bad token issuer might be getting called.  If this is the first time you are configuring high-trust apps then you can skip steps a & b below.

    a. Run Get-SPTrustedSecurityTokenIssuer.  If no Azure workflow is configured this command should return empty.  If you get any issuer apart from workflow, run below script to delete it.

    b. Remove-SPTrustedSecurityTokenIssuer (pass Id value from output of the above command).

    2. Create a new SPTruestedSecurityTokenIssuer by running below script, passing your SharePoint Developer site URL and Cert path (.cer) that you will use to sign the token (you need to create a self-signed cert).  For more information see: http://msdn.microsoft.com/en-us/library/fp179901.aspx.

    Take a note of the $issuerId = “447f40c6-99df-4d37-9739-5370102489f7” from the below script.  We’ll be using it later.

    param( 
                    [Parameter(Mandatory=$true)][string] $TargetSiteUrl,
                    [Parameter(Mandatory=$true)][string] $CertPath = $(throw "Usage: ConfigureS2SApp.ps1 <TargetSiteUrl> <Certificate>") 
    )
     
    # On error, stop
    $ErrorActionPreference = "Stop"
     
    # Add sharepoint snapin
    # add-pssnapin microsoft.sharepoint.powershell
    function ConfigureS2SApp([string]$TargetSiteUrl, [string]$CertPath)
    {
                    #write-host "Configuring with parameters $appTitle , $TargetSiteUrl , $CertPath"
                    write-host "you passed" $TargetSiteUrl $CertPath -foregroundcolor Green
                    $issuerId = "447f40c6-99df-4d37-9739-5370102489f7"
                    $spweb = Get-SPWeb $TargetSiteUrl
                    $realm = Get-SPAuthenticationRealm -ServiceContext $spweb.Site
                    $fullAppIdentifier = $issuerId + '@' + $realm
                    $certificate = Get-PfxCertificate $CertPath
     
                    New-SPTrustedSecurityTokenIssuer -Name $issuerId -Certificate $certificate -RegisteredIssuerName $fullAppIdentifier –IsTrustBroker
                    
                    #turning off https <optional> this will make our sharepoint site run on http and still work with high trust app.
                    $serviceConfig = Get-SPSecurityTokenServiceConfig
                    $serviceConfig.AllowOAuthOverHttp = $true
                    $serviceConfig.Update()
    }
     
    ConfigureS2SApp $TargetSiteUrl $CertPath
     
    # done
    write-host "S2S is now configured" -foregroundcolor Green

    Section 2: Enable SharePoint on LightSwitch app and publish

    1. Right-click the LightSwitch project and go to properties and choose SharePoint tab.

    2. Enable SharePoint on the project (this basically adds SharePoint related files to LightSwitch project e.g., SharePointLaunch.aspx etc.,).

    image

    3. Right-click on the project and click Publish.

    4. Select Provider-hosted in SharePoint options.

    image

    5. Select IIS server since we will not be using Azure to host LightSwitch app.

    image

    6. Select Create Package on disk from the next screen.

    image

    7. Select users must connect using Https option.

    image

    8. Choose the appropriate data settings for your LightSwitch app.

    image

    9. Select use a certificate for a high-trust configuration and provide the certificate details and issuer ID we generated in Section 1 of this post.

    image

    10. Choose the web app where LightSwitch will be hosted and provide Client ID (you can generate your own GUID using Visual Studio or PS).

    image

    11. Create app principal by following the below steps in PS.

    $clientId = "<Your Client ID>"
    $spweb = Get-SPWeb "http://mspx2013"
    $realm = Get-SPAuthenticationRealm -ServiceContext $spweb.Site
    $fullAppIdentifier = $clientId + '@' + $realm
    $appPrincipal = Register-SPAppPrincipal -NameIdentifier $fullAppIdentifier -Site $spweb -DisplayName "SimpleHTApp"
    Set-SPAppPrincipalPermission -Site $spweb -AppPrincipal $appPrincipal -Scope Site -Right FullControl

    12. The summary screen should look like below.

    image

    13. From the published folder, upload the .app file to SharePoint Developer Site.

    image

    14. Host the LightSwitch app in different IIS web (e.g., https://localhost:9090).

    15. When you click on the SampleLightSwitch app you will be redirected to the actual LightSwitch app that’s hosted in your IIS server.

    image

  • HOW TO: Deploy InfoPath List Forms for an External List using Visual Studio 2012 solution package

    This post is a contribution from Aaron Miao, an engineer with the SharePoint Developer Support team.

    Create a test site

    1. We create a SharePoint site collection named http://intranet.contoso.com/sites/testsite/testexternallist.

    **It’s good to use a site which does not have lot of stuffs, best would be to create a new team site or blank site.

    2. Activate the following site collection features:

         a. SharePoint Server Enterprise Site collection features

         b. SharePoint Server Standard Site collection features

    Prepare SQL Database table

    **You could use Northwind sample database

    3. Create a table in SQL database called TestTable.

    image

    4. Add some data to it.

    image

    Create an external content type and a list instance using SharePoint Designer 2013

    5. Open the test site using SPD 2013 and create an external content type ExternalTestCT (reference if you need it).

    image

    6. Create external list using SPD 2013 and choose to create InfoPath forms.

    image

    The result should look like this.

    image

    7. Verify external list works by browsing to it using SharePoint 2013 UI.

    image

    8. Make sure the external list displays data successfully in InfoPath forms.  “View Item” of the list will display an item in InfoPath form like this:

    image

    Prepare Visual Studio SharePoint 2013 project

    9. Now save the site as template without content using SPD 2013.

    image

    10. This will generate a WSP file in your site collection solution gallery.  Download a copy of this WSP and save it to local disk.

    image

    Create Visual Studio 2013 project and solution

    11. Create a Visual Studio 2013 project of type “SharePoint 2013 – Import Solution Package” and point to the saved WSP.  As a reference, this blog walks through the entire process.

    image

    **When there’s a warning about dependencies, click “Yes” to have VS 2012 automatically include all dependencies.

    12. Once you are done with these steps, you will have the external list instance, with its schema.  You will also have Modules with all the InfoPath forms and template.xsn.  In addition, you’ll see a PropertyBags module as well.  Your project should look like this:

    image

    13. Clean up unnecessary files

           a. Remove ListsExternalList1_pages item

           b. Remove 2 features (3 features are imported.  Retain the first feature you see from the top in the list of features and remove the other 2)     

           c. Make sure the feature includes items: List instances, Modules and PropertyBags.

    In the end, your project should look like this:

    image

    Details of each file

    **Make sure you verify that the external list name is same in the list instance and all the files (schema, module files).  There are lots of places the list name and its URL is used.

    14. ExternalList1/Elements.xml:

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <ListInstance FeatureId="{00bfea71-9549-43f8-b978-e47e54a10600}" 
                    TemplateType="600" 
                    Title="ExternalList1" 
                    Description="" Url="Lists/ExternalList1" 
                    CustomSchema="Files\Lists\ExternalList1\Schema.xml" 
                    HyperlinkBaseUrl="http://spdev1505/sites/TestSite" 
                    RootWebOnly="FALSE" xmlns="http://schemas.microsoft.com/sharepoint/">
            <DataSource>
                <Property Name="Entity" Value="ExternalTestCT" />
                <Property Name="EntityNamespace" Value="http://spdev1505/sites/testsite" />
                <Property Name="LobSystemInstance" Value="testdb" />
                <Property Name="SpecificFinder" Value="Read Item" />
            </DataSource>
        </ListInstance>
    </Elements>

    **<DataSource> provides information of the generated BDC model.

    15. ExternalList1/Schema.xml:

    <List Title="ExternalList1" 
          Direction="none" 
          Url="Lists/ExternalList1" 
          BaseType="0" Type="600" 
          MultipleDataList="FALSE" 
          DontSaveInTemplate="TRUE" 
          DisableGridEditing="TRUE" 
          NoCrawl="TRUE" 
          DisallowContentTypes="TRUE" 
          BrowserFileHandling="permissive" 
          NavigateForFormsPages="TRUE" 
          FolderCreation="FALSE" 
          DisableAttachments="TRUE" 
          Catalog="FALSE" 
          SendToLocation="|" 
          ImageUrl="/_layouts/15/images/itebl.png?rev=23" 
          xmlns:ows="Microsoft SharePoint" 
          xmlns:spctf="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms" 
          xmlns="http://schemas.microsoft.com/sharepoint/">
        <MetaData>
            <Fields>
                <Field DisplayName="BDC Identity" Hidden="FALSE" Name="BdcIdentity" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="BdcIdentity" Type="Text" ReadOnly="TRUE" />
                <Field DisplayName="TextCol" Hidden="FALSE" Name="TextCol" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="TextCol" Type="Text" ReadOnly="TRUE" Required="TRUE" />
                <Field DisplayName="DateCol" Hidden="FALSE" Name="DateCol" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="DateCol" Type="DateTime" />
                <Field DisplayName="BoolCol" Hidden="FALSE" Name="BoolCol" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="BoolCol" Type="Boolean" />
            </Fields>
            <Forms />
            <Views>
                <View DisplayName="ExternalTestCT Read List" DefaultView="TRUE" BaseViewID="1" 
                Type="HTML" MobileView="TRUE" MobileDefaultView="TRUE" ImageUrl="/_layouts/15/images/generic.png?rev=23" 
                XslLink="main.xsl" WebPartZoneID="Main" WebPartOrder="0" Url="Read List.aspx" SetupPath="pages\viewpage.aspx">
                    <XslLink>main.xsl</XslLink>
                    <Method Name="Read List" />
                    <Query>
                        <OrderBy>
                            <FieldRef Name="TextCol" />
                        </OrderBy>
                    </Query>
                    <ViewFields>
                        <FieldRef Name="TextCol" ListItemMenu="TRUE" LinkToItem="TRUE" />
                        <FieldRef Name="DateCol" />
                        <FieldRef Name="BoolCol" />
                    </ViewFields>
                    <RowLimit Paged="TRUE">30</RowLimit>
                    <Aggregations Value="Off" />
                </View>
            </Views>
        </MetaData>
    </List>

    **Type=”600” indicates this is an external list.  Fields are defined in the schema.

    16. Modules/ListsExternalListItem_/Files/Elements.xml:

    image

    17. PropertyBags/Elements.xml:

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <PropertyBag Url="Lists/ExternalList1/Item/template.xsn" ParentType="File" RootWebOnly="FALSE" 
                   HyperlinkBaseUrl="http://spdev1505/sites/TestSite" 
                   AlwaysCreateFolder="TRUE" 
                   xmlns="http://schemas.microsoft.com/sharepoint/">
        <Property Name="ipfs_streamhash" Value="WilYbGIFAHARhhugf7kJzQlo447iT2RkT/siF5/CimI=" Type="string" />
        <Property Name="vti_streamschema" Value="66" Type="int" />
      </PropertyBag>
    </Elements>

    **There are many properties in the file generated originally.  Only the above two are required.  Looks like they are related to InfoPath form activation and file persistence.

    In the end, you should see the artifacts like in the VS 2012 project attached to this blog post.

    Test the solution

    18. Deploy the project to another site.  You may not see the external list in the quick launch.  Navigate to site contents and click the external list.  You should see the list and InfoPath item view form.

    image

    image

    19. The view form URL should like like what’s shown below.  Notice that displayifs.aspx is used and not DispForm.aspx.

    http://intranet.contoso.com/sites/TestSite/Lists/ExternalList1/Item/displayifs.aspx?ID=__bk410047005600870047004300&Source=http%3A%2F%2Fspdev1505%2Fsites%2FTestSite%2FLists%2FExternalList1%2FRead%2520List%2Easpx&ContentTypeId=0x0&RootFolder=%2Fsites%2FTestSite%2FLists%2FExternalList1

    Hope this post was helpful!

    Sample VS2012 project for download

  • HOW TO: Deploy a provider hosted app as an Azure site

    This post is a contribution from Charls Tom Jacob, an engineer with the SharePoint Developer Support team.

    In this blog, I will describe the steps to deploy a provider hosted app on Windows Azure hosted site (same steps should work for any IIS sites for that matter).  The app will be deployed into SharePoint Online site, whereas the underlying business logic will reside on a separate server.  It could be an on-premise server or a server provided by a hosting company.  For this blog post, I decided to use a site hosted on Azure.

    1. Create a provider hosted app project in Visual Studio 2012.

    clip_image002

    2. Select ACS.

    clip_image004

    3. Navigate to your App Catalog site collection URL (/_layouts/15/appregnew.aspx).

    a. Generate a Client ID and Client Secret.

    b. Make sure to give correct values for AppDomain and Redirect URL. This should be corresponding to where you want to host your app web.

    clip_image006

    4. Publish the App project by specifying the same Redirect URL, Client ID and Client Secret as in the previous step.

    clip_image008

    5. This gives you the deployable units as below.

    a. Rename the .app file to .zip and verify that app manifest contains the correct Client ID.

    clip_image009

    6. Upload the app to the App Catalog site collection in your SharePoint site.

    clip_image010

    7. Modify the AppWeb web.config file to include the Client ID and Client Secret as shown below.

    clip_image011

    8. Deploy the web site to the desired location using any of the publishing methods available.

    clip_image012

    9. Add the app to one of the sites and launch it.

    clip_image013

    NOTE: You will run into “The parameter ‘token’ cannot be null or empty string” error if you make a mistake in the Client ID and/or Client Secret or redirect URL.

    Hope this walk-through was helpful!