Jake

SharePoint Developer

Homepage: http://jakistra.wordpress.com/

Content and Structure Report for All Checked Out pages

Under Content and Structure (_layouts/sitemanager.aspx) there are a set of views that allow you to filter items in your site.  For instance, “Checked Out To Me”, “Pending Approval” are just two of the out of the box views.  One report that is not there, but should be, is a view for all checked out pages by all users.  Happily, you can add your own custom views by editing the “Content and Structure Reports.”

From Site Actions, select “View All Site Content”

image

Click on “Content and Structure Reports”

image

You’ll see all of the canned reports listed:

image

Click “Add New Item” and enter the Report Title and CAML Query:

<Where><Geq><FieldRef Name=”CheckoutUser” LookupId=”TRUE”/><Value Type=”Integer”>0</Value></Geq></Where>

image

Save and close

image

To use the report, go to Site Actions > Manage Content  and Structure and change the View to the new “All Checked Out” report:

image

5 Comments

SharePoint Central Admin error – “The specified user or domain group was not found”

While working with SharePoint Central Admin, I tried to access the Service Applications page (“Manage Service Applications” from Application Management).  Before getting to the page, I received the error “The specified user or domain group was not found.”  I checked the SharePoint logs and found this exception:

“SPAce PrincipalName domain\test.user cannot be resolved. This ACE will not be effective. System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.”

(For blogging, purposes, I am using the name “domain\test.user”)  The Principal Name, “domain\test.user” happened to be an actual user that was no longer at the company.  It appeared that this user, was being used for one of the service application administrators.  I checked with Operations and indeed, “test.user” was purged from Exchange the day before.  Working with operations, we recreated the same user name.  We were unsure that this would work since the unique identifier of that user would be different, but it was worth a shot.  After that user was added, I was able to access the Service Applications page again.  Success! 

The next step was to remove the user as an admin from the service application.  For this situation, the User Profile service application was the problem.  I accessed the Administrators dialog and removed the user from the list of admins.

image

The same user was also listed in the “Connections Permissions for User Profile Service Application.” I removed the user from that list as well.

image

With the user removed from the service application, Operations purged that user again.  Afterward, I was able to access the Service Applications page without the error.

2 Comments

Powershell script for updating a publishing page Page Layout in a site collection

One of the page layout templates was changed in a SharePoint 2010 site collection that I was working on.  There were already over 300 pages that were creating using the old Page Layout.  Enter… Powershell!  It took about two hours to write this script (with help from The Google) but it will probably save a day of work updating all those pages individually through the UI.

The script takes three parameters, the old or current page layout name, the new page layout name and an optional –all parameter which will traverse all the sites of a site collection.  Enjoy.

# Description:
# Update the layout page for all matching pages of the current page layout
# Checkout, Change layout, Check-in pages in a site collection
#
# Syntax:
# ./UpdateLayoutPages [-PageLayoutCurrent] [-PageLayoutNew] [-all]
#
# Parameters:
# -PageLayoutCurrent     - The page layout that is currently in use and will be updated
# -PageLayoutNew        - The new page layout that pages will be updated to
# -all                     - Update subsites in the site collection
#
# Modifications:
# v1.0 - April 5th, 2011
# Initial version
#
# Settings
set-variable -option constant -name url  -value http://localhost   # Site collection
set-variable -option constant -name comment -value "Batch PageLayout Update"   # Publishing comment

# Function: Update-SPPagesPageLayout
# Description: Update a single page in a Publishing Web
# Parameters: publishingPage, pageLayout, comment
function Update-SPPagesPageLayout ([Microsoft.SharePoint.Publishing.PublishingPage]$publishingPage,
    [Microsoft.SharePoint.Publishing.PageLayout] $pageLayoutNew, [string]$comment)
{
    Write-Host "Updating the page:" $publishingPage.Name "to Page Layout:" $pageLayoutNew.Title
    $publishingPage.CheckOut();
    $publishingPage.Layout = $pageLayoutNew;
    $publishingPage.ListItem.Update();
    $publishingPage.Update()
    $publishingPage.CheckIn($comment);
    if ($publishingPage.ListItem.ParentList.EnableModeration)
    {
        $publishingPage.ListItem.File.Approve("Publishing Page Layout correction");
    }
}

# Function: Update-AllSPPagesPageLayouts
# Description: Loop through all the pages in a Publishing Web and update their page layout
# Parameters: web, pageLayoutCurrent, pageLayoutNew, comment
# comment Comment to accompany the checkin
Function Update-AllSPPagesPageLayouts ([Microsoft.SharePoint.SPWeb]$web, [Microsoft.SharePoint.Publishing.PageLayout]$pageLayoutCurrent,
    [Microsoft.SharePoint.Publishing.PageLayout]$pageLayoutNew, [string]$comment)
{
    #Check if this is a publishing web
    if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web) -eq $true)
    {
      $pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);
      $pubcollection=$pubweb.GetPublishingPages()
      #Go through all pages checking for pages with the "current" page layout
      for($i=0; $i -lt $pubcollection.count; $i++)
      {
        if($pubcollection[$i].Layout.Title -eq $pageLayoutCurrent.Title)
        {
            Update-SPPagesPageLayout $pubcollection[$i] $pageLayoutNew $comment
        }
      }
    }
    $web.Close();
}

# Check Parameters
if(($args[0] -ne $null) -and ($args[1] -ne $null))
{
    Write-Host "** Update Layout Pages from-" $args[0] "-to-" $args[1] "-on URL" $url
    $pageLayoutNameCurrent = $args[0];
    $pageLayoutNameNew = $args[1];

    $site = new-object Microsoft.SharePoint.Publishing.PublishingSite($url)

    Write-Host "Checking if both page layouts exist in the site..."
    # Check if the current pagelayout exists in this site collection
    $pageLayouts = $site.GetPageLayouts($true);

    $pageLayouts | ForEach-Object {
        if ($_.Title -eq $pageLayoutNameCurrent)
        {
            Write-Host "Found CURRENT page layout: " $pageLayoutNameCurrent
            $pageLayoutCurrent = $_;
        }
    }

    # Check if the new pagelayout exists in this site collection
    $pageLayouts | ForEach-Object {
        if ($_.Title -eq $pageLayoutNameNew)
        {
            Write-Host "Found NEW page layout: " $pageLayoutNameNew
            $pageLayoutNew = $_;
        }
    }      

    # Do not continue if the either pageLayout does not exist
    if(($pageLayoutCurrent -ne $null) -and ($pageLayoutNew -ne $null))
    {
        # Update all subsites
        if($args[2] -eq "-all")
        {
         $site.Site.allwebs | foreach {
            Write-Host "Checking Web: " $_.Title
            Update-AllSPPagesPageLayouts $_ $pageLayoutCurrent $pageLayoutNew $comment
            }
        }
        else
        {
         $site.rootweb | foreach {
            Write-Host "Checking Web: " $_.Title
            Update-AllSPPagesPageLayouts $_ $pageLayoutCurrent $pageLayoutNew $comment
            }
        }
    }
    Write-Host "**Done"
}
else
{
    Write-Host "Missing arguments.  Please check your parameters"
}
#End

13 Comments

Error occurred in deployment step ‘Recycle IIS Application Pool’: The local SharePoint server is not available. Check that the server is running and connected to the SharePoint farm.

If you get this error when deploying a SharePoint solution in Visual Studio on a SharePoint server, check that you have db_owner SQL Server permissions on the SharePoint content databases.

Update: I received a similar error to the one listed above:
Error occurred in deployment step ‘Recycle IIS Application Pool’:<nativehr>0x80070005</nativehr><nativestack></nativestack> Access denied.
For this error, make sure that you are a Site Collection Administrator

2 Comments

Displaying a SharePoint Modal Dialog window from SPGridView

I recently built a web part that required a list of announcements with summaries to be presented to a group of users.  Additionally, there was detailed content that was to be displayed in a Pop-up type window.  I used a gridview to display the list, which was pulled in from a web service and passing in a datatable.  That part was rather easy, but the data for the details was stored in a column that contained HTML formed text.  My first thought was to pass that to a javascript function that would call the method for displaying a SharePoint dialog: SP.UI.ModalDialog.showModalDialog();

When I added the HTML as a parameter to the javascript function, the result of doing that was rather odd.  The HTML text was displayed in the web part itself, which was not going to work.  I tried a few workarounds like encoding the HTML text and such, but I did not get good results with that either.  Instead, I knew that I had the ID for the items that I was displaying in the list.  I could pass in the ID to the dialog page and retrieve the HTML text at that point.  Unfortunately, it required two round trips to the web service (and subsequently the SQL Server).

Another issue when displaying the dialog was that the page that I was displaying contained all the elements of the master page that typical pages display (header, footer, etc).  This made the dialog too busy for the simple task it was asked to do.  To fix this, I added the MasterPageFile attribute to the Page directive which overrides DynamicMasterPageFile attribute.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AnnouncementPage.aspx.cs" Inherits="MyPages.WebParts.Layouts.AnnouncementPage" DynamicMasterPageFile="~masterurl/custom.master" MasterPageFile="~/_layouts/applicationv4.master" %>

In the end, a uncluttered summary list and detailed model dialog:

image

image

Code that made it happen:

<script type="text/javascript">
    function OpenDialog(aid) {
        var options = SP.UI.$create_DialogOptions();
        options.url = "/_layouts/MyPages/AnnouncementPage.aspx?announcementId=" + aid;
        options.width = 560;
        options.height = 480;
        options.dialogReturnValueCallback = Function.createDelegate(null, OnCloseDialog);
        SP.UI.ModalDialog.showModalDialog(options);
    }
</script>

<div class="spgridannounce">
    <SharePoint:SPGridView ID="spGridViewAnnouncements" runat="server" AutoGenerateColumns="false"
        ShowHeader="false">
        <HeaderStyle BackColor="Transparent" ForeColor="#08630C" />
        <AlternatingRowStyle BackColor="Transparent" />
        <RowStyle BackColor="Transparent" ForeColor="#BF5629" />
        <Columns>
            <asp:TemplateField>
                <HeaderTemplate>
                    Announcement</HeaderTemplate>
                <HeaderStyle />
                <ItemTemplate>
                    <a href='javascript:OpenDialog(<%# Eval("announcement_id")%>)'>
                        <%# Eval("subject") %>
                    </a>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </SharePoint:SPGridView>
</div>

Leave a comment

Your client does not support opening this list with Windows Explorer

You are happy working in SharePoint, creating document libraries and new pages with riveting content, when you decide you’d like to open up a library in Explorer view and blamo!

Yourclientdoesnotsupport2

There are various theories on this problem, but for me, the solution was to activate the “Desktop Experience” feature from Server Manager.  My development environment is on Windows Server 2008 Standard and SharePoint 2010.

Open Server Manager, Add a Feature:

servermgr1

Select Desktop Experience: 

servermg2

Reboot the server and you should be able to open from the File Explorer until the cows come home:

servermgr3

Leave a comment

Display SharePoint list items based on date range

There was a request to display items (“How-To Tips”) based on a date range.  Seemed like a reasonable request, but I didn’t see anything out of the box that provided this functionality.  To get this done, the obvious choice was to use the Content Query Web Part (CQWP) and create a custom list that contained the tip items.  In the custom list, I created the columns: Tip Description, Tip URL (in case a tip linked to another page/site), Display Start Date and Display End Date and Background Image (the requester also wanted a pretty image for the background of this web part).

image

Now that I had those columns to work with, I added a CQWP to the page and edited the web part to use my custom list:

image

To get the date range functionality, I used the Additional Filters section and my Date columns to filter on items with a Display Start Date less than or equal to [Today] and a Display End Date greater than or equal to [Today]. 

image

All that is left to do is add items to the list that have the correct start and end dates and the tip(s) appear on the web part:

image

image

There is more to do with getting the background image.  I will blog that someday.

Leave a comment

KeywordQuery Error: Property doesn’t exist or is used in a manner inconsistent with schema setting

In the following code of a web part that was doing a custom KeywordQuery search, I received the error “Property doesn’t exist or is used in a manner inconsistent with schema settings.”  The Properties that I was adding to the KeywordQuery had not yet been mapped in the Search Service Application, Metadata Properties:

//Get associated search service application
SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy
                    (SPServiceContext.GetContext(SPContext.Current.Site));

                //Use Keyword Query
                Microsoft.Office.Server.Search.Query.KeywordQuery keywordQuery = new Microsoft.Office.Server.Search.Query.KeywordQuery(proxy);
                keywordQuery.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;

                //Return following properties          
                keywordQuery.SelectProperties.Add("ProjectCreator");
                keywordQuery.SelectProperties.Add("ProjectName");
                keywordQuery.SelectProperties.Add("ProjectDescription");
                keywordQuery.SelectProperties.Add("ProjectStage");
                keywordQuery.SelectProperties.Add("Path");
                keywordQuery.SelectProperties.Add("Title");
                keywordQuery.SelectProperties.Add("Id");
                keywordQuery.SelectProperties.Add("SiteName");

To map these properties, go to the Search Service Application –> Metadata Properties page in Central Administration –> Application Management.
Mapp_Crawled_Property_0

Select “New Managed Property”

Mapp_Crawled_Property1

Type the new Managed Property and add a mapping

Mapp_Crawled_Property

In my case, I am mapping to properties that were promoted from an InfoPath form.

Mapp_Crawled_Property3

Once the property is mapped, re-run an incremental or full crawl on your content source which contains the property

Leave a comment

Error occurred in deployment step Add Solution: Value does not fall within the expected range

A SharePoint 2010 solution I was working on contained several different types projects (MasterPage, ContentTypes, EventReceivers).  At one point, I started getting this error:  “Error occurred in deployment step Add Solution: Value does not fall within the expected range.” 

By unloading projects I narrowed it down to my ContentType feature.  The ID of the content type had a typo (I left a closed brace sign at the end of the ID).  While googling for this error, there wasn’t an exact match for my typo, rather it was the method to isolate the problem, which is to unload projects and features until I found the culprit.

<ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2006748130EC3DB064584E219954237AF3900F7AEFF
AB848C45AE85AC577F52131053}"
               Name="Three Columns Main"
               Group="My Pages"
               Description="Main Page with three columns"
               Version="0"
               Inherits="TRUE"
               Overwrite="TRUE">
    <FieldRefs>
      <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" />
      <FieldRef ID="{888D470D-BF80-4DF2-A2D6-72EBDFF90DE1}" Name="PortalHeaderText" />
    </FieldRefs>
  </ContentType>

3 Comments

Visual Studio 2010 properties window – commands & descriptions missing

In the Visual Studio 2010 Beta, the Properties Window contained a sub-window that enabled the generation of handlers for workflow properties (not just workflow properties, but any item that had an a event property).  I found this to be a quick and consistent way to create those event handling stubs.  Upon upgrading to the release version of VS2010, I noticed that the command window was missing:

VS_NoCommand

To display the commands, bring up the context menu for the properties window (right click) and check the commands option.  The same goes for descriptions. 

vs_Commands

Leave a comment