Friday, 2 August 2013

SharePoint 2007 - Cannot access "Page Settings" area in Publishing site

Here's an odd thing. I wanted to change the Page template of a SharePoint page that was displaying in an old, outdated template. But when I went Edit Page, then Page > Page Settings ... 




... I wasn't seeing the familiar Page Settings page. I was seeing this:




No sign of my picklist of Page Templates at all. I knew I had encountered this problem before, but couldn't remember what the solution was, so I got on to trusty Google, figuring someone is bound to have the answer to this vexing issue. But no ... nothing doing.

I tried going to the Pages Directory and seeing if Editing Properties of the page would help, but that got me nowhere.

Then, running out of options, I fired up SharePoint Designer and navigated to the sub-site. And there it was! 




The dad-blasted Page Layout was detached, obviously from some earlier Designer fiddling and I'd forgotten to reattach. Simply reattaching the Page Layout fixed the problem and I was able to access the Page Layout picklist in the Page Settings area.



It might seem screamingly obvious but then, you can't always remember everything, and incredibly, no one has posted an explanation for this problem that crops up in the first ten screens of a Google search. 

So hopefully, this will save someone thrashing around, trying to figure out why they can't change the Template for a SharePoint Publishing page.

Monday, 8 July 2013

Place a Picture Library SlideShow on a SharePoint 2007 page

I wanted to embed a Picture Library as a SlideShow in a SharePoint 2007 page, but when I checked the Microsoft web site, their coverage of the SharePoint 2007 Picture Library function didn't have the information I needed. So, I had to figure it out for myself.

So here's what I did to embed a Picture Library SlideShow on the page ...

  1. First, I created a SharePoint Picture Library in the normal way and loaded up the images.
  2. Next, in the newly-created Picture Library, I selected View Slide Show from the Actions menu.


  3. This brings up the Slide Show in a new browser window. I right-clicked on the Slide Show and selected Properties.


  4. I highlighted the URL of the Slide Show and copied to the clipboard with the ctrl-c function.


  5. Then I placed a Page Viewer Web Part on the selected SharePoint page and added the URL from the clipboard. You may have to adjust the height of the Page Viewer Web Part to accommodate the size of image you're using.
That's it ...

Tuesday, 21 May 2013

Setting default values for Content Types on creating a new page


While trying to set up a facility in SharePoint to email around summaries of the week's top news stories, I ran into a strange problem.

If you've read my previous post, you'll recall that I had set up a sub-site in SharePoint to hold the news articles - each article was on a new page and the pages incorporated metadata stored in Content Types created for that purpose.

I'd built the pages that way so that the non-technical News publishers would be able to set vital meta-data for each story without having to go the 

Site Actions > View all Site Content > Pages 

route to get to the Edit Properties function.

All that went fairly smoothly - apart from a small glitch around retrieving the current Page URL (see the previous Blog posting) - and we proudly launched our new News facility.

The next glitch came when one of the publishers was compiling the weekly round up of top News stories. I'd made a page containing a DVWP which looked at the Pages folder that contained all the News stories and displayed just those where a value for "weekly roundup email position" had been set. This is a Content Type that contains a choice of values "1st story, 2nd story, etc". The publisher creates a new story, then selects a value for "weekly roundup position" from a pick list. If the story isn't required in the weekly round up then they leave the value as "Select a position for email". The Content Type had the same value set as the default value.

The issue was, when the publisher created a new story, the value for "weekly roundup position" was blank by default. Where was the default value?


Above left is what the metadata setting looked like when a new page was created, but we needed it to look like the above right image, with a default value displayed in the Roundup picklist.

Everything looked like it was set up correctly but it wasn't working ... so had a trawl around on Google and was unable to find anyone else with the same problem. Then I chanced on a site where someone was talking about not seeing default values on Content types. After following a series of links and putting the information together, it became apparent to me what was causing the problem. Turns out you have to make the group of Content Types the Default Content Type Group for the List you're looking at.

So here's what I did ...

I had set up my new Content Types in the Article Page group. So I drilled down to the Content Type and made sure the default value was set to what I wanted.



Next I went back to the List - in this case, the Pages Directory that held the News articles - and from the Settings menu selected Document Library Settings.

Then I found the Content Types section - note that the Page Content Type is set as the default - and clicked on the link Change new button order and default content type.



Now it's not screamingly obvious but what you have to do is bring the Content Type Group that holds the Content Types you want to display the Default Values for up to the top of the list by setting its value to "1", then clicking OK.



That's it. The Content Types section should now look like this, with Articles at the top and ticked as the Default Content Type.



Now when you create a new page, the default values you set in the Content types will be added to the metadata for that page, unless (or until) you choose a different Content Type value.

Hope this helps someone ...

Friday, 12 April 2013

Adding page-specific icons to a SharePoint page


I was building a news function for SharePoint 2007 that is a bit more sophisticated than the OOTB Announcements list. I figured I could make each news story a new page, then use Content Types to hold the metadata for each page that identify the news stories by type (ie, Business, Community, HR), the position they'd appear on on the Home page and whether they were a critical story that needed to be held in a DVWP listing so it wouldn't drop off people's radar.

The reason I wanted to use Content Types (as opposed to simply adding columns to the Pages directory) was I wanted the end-users to be able to set the metadata values on the same page that they would add the headline, summary, body text and picture on.
This arrangement allows the end-users to set
metadata for the news detail page that determines
how the news articles will appear in other web parts
around the site

All this seemed pretty easy ... and I don't want to cover the process here in detail, as you can find how to do this on any number of other sites.


But a problem arose when I had a further requirement to set icons for each news story depending on which company values related to the subject matter of the story.

So I set up a Content Type for the icons ("StrategicLevers") and made it a tickbox choice so the end users could tick a box to make that icon appear on the page.

Next I added a Data View Web Part to the page template that looked at the Pages directory where the news detail pages would be stored, and called the values from the Content Type I'd already set up to hold the values for the icon images.

Then I had to find a way of identifying the current page in the DVWP that would display the correct icons. This at first appeared to be a pretty easy task. I would just use the in-built SharePoint parameter for the page URL called, with customary Microsoft creativity, "PageURL".

So I set a binding up for the PageURL parameter and then called the parameter further down the page, like this:

<ParameterBinding Name="PageURL" Location="Postback;Connection;CAMLVariable/>

in the ParameterBindings section, then added the Parameter further down the page, like this: 

<xsl:param name="PageUrl" />

at the top of the StyleSheet section.

After that, you should be able to use the PageURL Parameter return a value for the current page within the page ... 

In my case I was going to use the parameter to filter out all the values that weren't the current page. So I set up a a test using Choose/When, like this:

<xsl:choose>
<xsl:when test="@FileRef = $PageURL">
</xsl:when>
</xsl:choose>

What this does is that the DVWP iterates through all the pages in the Pages directory, comparing each page URL with the current page's URL and only displaying when there's a positive match. So far, so good ... except this is the point where I should have checked what value is being returned by this filtering process, perhaps by inserting:

<xsl:value-of select="@StrategicLevers">

to see what value came back. But I didn't. I pressed on and started adding the Choose/When statements that would display the icons according the values set in the StrategicLevers Content Type.

The way I wanted the function to work was that the icon would appear greyed out if the tickbox was unticked and in full effect if the box was ticked. So I did this:

<xsl:choose>
<xsl:when test="contains(@StrategicLevers, 'Solutions')">
<img src="/newsImgs/4_Creative_on.png"/>
</xsl:when>
<xsl:otherwise>
<img src="/newsImgs/4_Creative_off.png"/>
</xsl:otherwise>
</xsl:choose>

for each icon. In this case, "Solutions" is the value of that icon's tickbox. You'd have to change that value for each icon.

Next step, do a test. So I saved the template then opened a news detail page in my browser and ticked a couple of the icon tickboxes, but all the icons remained stubbornly greyed-out.

What followed was two days of frustrating trouble-shooting until I stumbled across a solution.

Even though I could see a value for the PageURL parameter in the Design view of Sharepoint Designer (SPD), the value wasn't displaying in the browser. I couldn't think of any reason why that would be so, but in the end accepted that it was so and started looking for another way to call the value for the current page so I could use it as a filter value.

By blind luck, I found a mention on Marc Anderson's blog about a Server variable that did the same thing.

So I got rid of the PageURL parameter binding and replaced it with this one:

<ParameterBinding Name="PageAddr" Location="ServerVariable(URL)" DefaultValue=""/>

...replaced the parameter further down the page with the new one, like this:

<xsl:param name="PageAddr" />

... and amended the parameter name in the first Choose/When routine:

<xsl:choose>
<xsl:when test="@FileRef = $PageAddr">
</xsl:when>
</xsl:choose>

Success! This worked fine in the browser, but perversely, didn't work at all in SPD Design view ... I still have no idea why Microsoft thought this was a good idea.

Friday, 7 September 2012

Modifying the size of an image stored in a Content Type

Here's a puzzle. We wanted to call a SharePoint Content Type that holds an image, but to use code to force the image to present at a different size. But the XSL call in the SharePoint page looks like this:

<PublishingWebControls:DateTimeField FieldName="PublishingPageImage" runat="server" />

... so there's not a lot of scope to add in height and width attributes. Using the SharePoint web browser image size controls wasn't an option because we needed the same Content Type image to appear at full size elsewhere.

After a bit of searching on Google, we realised that this wasn't going to be solved for us. So we looked back over our code snippets and found a way of splitting up the code that SharePoint renders into its component parts. Here's how we did it.

1. Create and populate a variable with the image URL from a Publishing Image (content type). Like this:

<xsl:variable name="picURL" select="substring-before(substring-after(@PublishingPageImage, 'src=&quot;'), '&quot;')" />

2. Now call the variable and drop it into an image call with different size attributes, like this:

 <img height="75" width="100">
   <xsl:attribute name="src">
     <xsl:value-of select="$picURL" />
   </xsl:attribute></img>


SPDesigner won't like the closing img tag, but just ignore the yellow highlight!

Thursday, 23 August 2012

Concertina - reveal and hide text by click

In our SharePoint 2007 site collection we've had quite a few requests for FAQs that open when the question is clicked then snap shut when the question is clicked again. This is a fairly simple effect to achieve in a Data View Web Part.


To contain the FAQ questions and answers, create a custom list and add a single additional multi-line text column, Answer, to hold the answers. You'll use the Title column to hold the questions. If you expect the FAQs to divide into sections, you can another field called Category, perhaps as a Choice field, and add your categories as choice values.

Now add one or two questions and answers (and if applicable, assign a Category value to each q&a) so you'll be able to see content as you build your Data View Web Part.

Next, create a Data View Web Part on the appropriate page and insert data from the fields Title and Answer.

Finally, replace the table-row that's displaying your list data in the DVWP with this code:

    <xsl:if test="position() = 1">
     <tr>
      <td>
       <h2><xsl:value-of select="@Category"/></h2>
      </td>
     </tr>
     </xsl:if>
     <tr>
      <td class="ms-vb"><span style="cursor:pointer" onclick="if (this.parentNode.parentNode.nextSibling.style.display=='none') this.parentNode.parentNode.nextSibling.style.display='block'; else this.parentNode.parentNode.nextSibling.style.display='none';" >
       <h3 style="margin:0px"><img src="/masterPageTemplateImages/miniplus.gif" />&#x9;<xsl:value-of select="@Title" /></h3></span></td>
 
     </tr>
     <tr style="display:none">
      <td class="ms-vb">
       <xsl:value-of select="@Answer" disable-output-escaping="yes" /></td>
 
     </tr>
     <tr><td><img src="/masterPageTemplateImages/spacer.gif" height="10" width="50"/></td></tr>


The "miniplus.gif" image is optional, but helps clarify for the users that the question is clickable to reveal the answer and the final table cell with the spacer.gif just adds a little space between the q&as.

That's it - job done!

Wednesday, 2 November 2011

Hiding fields in NewForm.aspx

Sometimes you may want to set a field in a SharePoint 2007 list to pre-populate with a default value. However, SP still allows your site visitors to alter the value via the New Item form. For example, when I want to capture data supplied by the visitor, but I know only admin staff will be looking at the data, I'll often assign the default value of "Edit Details" to the Title field, so that admin staff know to click on the "Edit Details" hyperlink to see details of that List row.

One answer is to edit the NewForm.aspx page so that the Title field is not displayed. That way site visitors can't change the pre-set default value for the field.

Here's how ...

1. Open SharePoint Designer and navigate to the site that contains the list or document library you wish to customize.

2. Expand the folder named “Forms” under the desired list or document library. You should see about four .aspx pages (AllItems.aspx, EditForm.aspx, NewForm.aspx, etc)


Edit the NewForm.aspx file, and add the Javascript directly ...
3. Check out and open the NewForm.aspx page and switch to the “code” view to edit the HTML of the page.

4. Paste this JavaScript code immediately below the the following HTML tag (usually line 14):
 <asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”> 

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFields");
function findacontrol(FieldName) {
   var arr = document.getElementsByTagName("!");
   // get all comments
   for (var i=0;i < arr.length; i++ )
   {
      // now match the field name
      if (arr[i].innerHTML.indexOf(FieldName) > 0)
      {         return arr[i];      }
   }
}

function hideFields() {
   var control = findacontrol("Title");
   control.parentNode.parentNode.style.display="none";
   control = findacontrol("Document Link");
   control.parentNode.parentNode.style.display="none";
   control = findacontrol("PublishDate");
   control.parentNode.parentNode.style.display="none";

}
</script>


This will add the JavaScript to the HTML inside the content placeholder tag. 
Note: be sure to include the entire script above, including the <script> and </script> tags.


5. Modify the “hidefields()” section of the JavaScript code to refer to each SharePoint list field name to hide.  For example, the code sample above will hide the SharePoint fields named Title, Document Link, and PublishDate.  Notice that you do not need to worry about internal field names or field types like other JavaScript techniques, you simply need to know the name of the field.

6. Save the changes and check the page back in.  Select “Yes” when prompted to “… customize the page from the site definition …”

7. Test the form

Please note - this method doesn't work for SharePoint Online/2013/2016.

If you're using SP Online, you'd need to add a different JavaScript function.

Try this:

<script language="javascript" type="text/javascript">

$(document).ready(function() {

   {
    $('nobr:contains("Title")').closest('tr').hide();
    $('nobr:contains("Document Link")').closest('tr').hide();
    $('nobr:contains("PublishDate")').closest('tr').hide();
   }

});

</script>

You can add a SharePoint 2016 Script Editor Web Part to the List Form page to hold the above JavaScript ... it's less cumbersome than planting the script in Site Assets and referencing it with a Content Editor Web Part. 

Hope this helps someone.