Category Archives: MOSS 2007

SharePoint 2007 – Get SPList Object by Url

I want to get a reference to a SPList object associated with a given list url.  This method works with any of the url’s associated with the list, including view page url’s, or list form url’s. 

This should be much easier to achieve by using the object model, in my opinion.  String parsing of the url is not my favorite, but I couldn’t find a better way to accomplish it. 

If you know of an easier way to accomplish this, please leave me a comment.  Otherwise, you can steal this from me, if you want it!

/// <summary>
/// Gets an SPList based on the url to the list
/// </summary>
/// <param name="listUrl">Full url to the list</param>
/// <returns>SPList object, null if list is not found</returns>
public SPList GetListByUrl(string listUrl)
{
    SPList list = null;

    try
    {
        using (SPSite site = new SPSite(listUrl))
        {
            if (site != null)
            {
                // Strip off the site url, leaving the rest
                // We'll use this to open the web
                string webUrl = listUrl.Substring(site.Url.Length);

                // Strip off anything after /forms/
                int formsPos = webUrl.IndexOf("/forms/", 0, StringComparison.InvariantCultureIgnoreCase);
                if (formsPos >= 0)
                {
                    webUrl = webUrl.Substring(0, webUrl.LastIndexOf('/', formsPos));
                }

                // Strip off anything after /lists/
                int listPos = webUrl.IndexOf("/lists/", 0, StringComparison.InvariantCultureIgnoreCase);
                if (listPos >= 0)
                {
                    // Must be a custom list
                    // Strip off anything after /lists/
                    webUrl = webUrl.Substring(0, webUrl.LastIndexOf('/', listPos));
                }
                else
                {
                    // No lists, must be a document library.
                    // Strip off the document library name
                    webUrl = webUrl.Substring(0, webUrl.LastIndexOf('/'));
                }

                // Get the web site
                using (SPWeb web = site.OpenWeb(webUrl))
                {
                    if (web != null)
                    {
                        // Initialize the web (avoids COM exceptions)
                        string title = web.Title;

                        // Strip off the relative list Url
                        // Form the full path to the list
                        //string relativeListUrl = listUrl.Substring(web.Url.Length);
                        //string url = SPUrlUtility.CombineUrl(web.Url, relativeListUrl);

                        // Get the list
                        list = web.GetList(listUrl);
                    }
                }
            }
        }
    }
    catch { }

    return list;
}

Enjoy!

  del.icio.us it!

digg it!

reddit!

technorati!

yahoo!

SharePoint TechFest 2009 – Dallas, TX

I want to thank everyone who attended my session on SharePoint Workflow with Visual Studio at our TechFest event yesterday.  Please feel free to post any comments (good or bad) about my presentation or the event. 

Demo source code is posted on Nakido until the Techfest site is updated with session content.

SharePoint WorkFlow with Visual Studio – Downloads

SharePoint WorkFlow with Visual Studio – References


  del.icio.us it! digg it! reddit! technorati! yahoo!

SharePoint 2007 100% CPU Spike – Blue Screen 0x0000001d

Problem

SharePoint 2007 Web Front End (WFE) servers crashing repeatedly.  Environment is SharePoint 2007 (MOSS Enterprise) 64-bit running on Windows Server 2008 Standard.  Server was crashing repeatedly with CPU spiking to 100%, blue screen, and server rebooting itself.  System log showing BugCheck event (1000) entry with code 0x0000001d:

The computer has rebooted from a bugcheck.  The bugcheck was: 0x000000d1 (0xfffff9802ea0ef50, 0x0000000000000002, 0x0000000000000000, 0xfffffa6004e06ed9). A dump was saved in: C:\Windows\MEMORY.DMP.

Resolution

After a lot of troubleshooting, it turns out it was Trend Micro Common Firewall Driver (Trend Micro OfficeScan Client 8.0).  When we disabled the firewall, problem resolved.

  del.icio.us it! digg it! reddit! technorati! yahoo!

Visual Studio 2008 Workflow Project Wizard – SharePoint Not Installed

Problem:

I’m creating a SharePoint Sequential Workflow using Visual Studio 2008 (SP1) with .Net 3.5 SP1 installed.  This is on a Windows 2003 R2 VPC with SharePoint 2007 (MOSS Enterprise) installed on the local machine for development.  A Collaboration Portal is installed on a web site with host headers (portal) assigned to port 80.

When I create a new workflow project, the wizard asks for a path to the SharePoint site.  I type in my url (http://portal in my case), and the project wizard fails, saying “SharePoint server not installed. Please run Microsoft Office SharePoint Server 2007 setup.”  

VS2008WF-SharePointNotInstalled

I’m logged in as the farm administrator.  I thought it might be a permissions issue (my farm admin doesn’t have full rights on the domain), so I went back and gave it full Domain Admin rights in case that was the problem.  Still failing!!

What the hell?

Resolution:

It turns out that the wizard does some funny business behind the scenes, calling the database directly.  When I give my development account (farm admin) account full rights (dbo) to the SharePoint content database for my portal site, bingo!  Works like a champ. 

After only an hour or two spinning my wheels.  Sigh….


  del.icio.us it! digg it! reddit! technorati! yahoo!

SharePoint 2007 API – How To Change Layout and Publish Page

The hardest part about this (by far) is figuring out how to publish the page after you’ve made your changes.   Every time I need to do it, I have to dig up some old code.

Thought I’d blog it this time, to make it easier on myself next time around.

using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
...

using (SPSite site = new SPSite("http://portal"))
{
    SPWeb web = site.RootWeb;

    // Check to ensure the web has publishing turned on
    if (!PublishingWeb.IsPublishingWeb(web))
    {
        throw new ApplicationException("Web does not have publishing enabled");
    }

    // Get a reference to the publishing web and publishing site    
    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
    PublishingSite pubSite = new PublishingSite(web.Site);

    // Get page layout from the page layouts collection    
    PageLayoutCollection siteLayouts = pubSite.GetPageLayouts(false);
    PageLayout myLayout = siteLayouts["/_catalogs/masterpage/MyLayout.aspx"];

    // Get a reference to a publishing page
    PublishingPageCollection pages = pubWeb.GetPublishingPages();
    PublishingPage page = pages["pages/default.aspx"];
    
    // Check out the list item as needed
    bool forceCheckout = page.ListItem.ParentList.ForceCheckout;
    if (forceCheckout)
    {
        // Is the page checked out?
        if (page.ListItem.File.CheckedOutBy != null)
        {
            // Throw an exception if the page is checked out
            string pageCheckedOut = string.Format("Page {0} is checked out by {1}", page.Url, page.ListItem.File.CheckedOutBy);
            throw new SPException(pageCheckedOut);
        }

        // Check out the page
        page.CheckOut();
    }

    // Change the page layout
    page.Layout= myLayout;

    // Update the page and check in changes
    page.Update();

    // Publish the page
    // This handles the page checkin and publishing the draft
    ApprovePublishingPage(page, "Modified page layout");

}

/// <summary>
/// Approves changes to a publishing page
/// </summary>
/// <param name="page">PublishingPage with changes to be published</param>
/// <param name="comment">Comment associated with the change</param>
public void ApprovePublishingPage(PublishingPage page, string comment)
{
    // Check in the page if required
    SPFile pageFile = page.ListItem.File;
    if (pageFile.Level == SPFileLevel.Checkout)
    {
        pageFile.CheckIn(comment, SPCheckinType.MajorCheckIn);
    }

    // Skip these steps if the parent list doesn't support moderation
    if (page.ListItem.ParentList.EnableModeration)
    {
        // If page is in "pending" status, approve it
        SPModerationInformation modInfo = page.ListItem.ModerationInformation;
        if (modInfo.Status == SPModerationStatusType.Pending)
        {
            pageFile.Approve(comment);
        }

        // If page is in draft status, publish it
        if (modInfo.Status == SPModerationStatusType.Draft)
        {
            pageFile.Publish(comment);
        }
    }
}

Enjoy!

  del.icio.us it! digg it! reddit! technorati! yahoo!

SharePoint 2007 (MOSS) – How To Determine Service Pack Version

So, what version of SharePoint 2007 is on this server?  Sounds like an easy question, doesn’t it?  Oh, I forgot, this is SharePoint!

SharePoint Server 2007 (including MOSS 2007) or WSS 3.0

Correct Methods

  • Central Administration > Operations > Servers In Farm > Database Schema Version – You will see the Database Schema Version in the top of the screen and a list of servers with the version numbers listed in the relevant column against each server in the farm
  • Site Settings > Modify All Site Settings > Site Information > Database Schema Version – You will see the schema version of the site content database
  • Query the Versions table of the farm configuration database – The entries in this table will show the version number and the date it was applied to the farm

Misleading Methods – The following methods are documented all over the web, but your results may be misleading

  • IIS Web Site Properties > HTTP Headers Tab >  Custom HTTP headers box which displays a version number – This shows the build version of MOSS at the time the Virtual Directory [Web Application] was created, which is probably not what you’re looking for.
  • Add / Remove Programs – Select Microsoft SharePoint Server 2007 or Windows SharePoint Services 3.0 > Click here for support information.  This will show the current version of the software installed on a WFE server, but it does not always update and may differ from other servers on the farm.  For better results, use the methods listed above instead.
Cumulative Update KB956056 & KB956057 12.0.0.6327
Infrastructure Update KB951695 & KB951297 12.0.0.6318
SP1 + KB948945 12.0.0.6303
SP1 + KB941274 12.0.0.6301
SP1 + KB941422 12.0.0.6300
SP1 12.0.0.6219
October 2007 public update 12.0.0.6039
August 24, 2007 hotfix 12.0.0.6036
RTM 12.0.0.4518
Beta 2 12.0.0.4017
Beta 2 TR 12.0.0.4407
Office 12 PDC Pre-beta 12.0.0.311

 

Running a Prior Version Of SharePoint?

If you’re unfortunate enough to be running an older version of SharePoint (SharePoint Portal Services 2003, 2001, SharePoint Team Services, or WSS 2.0), please see SharePoint Portal Services / Team Services – Determine Service Pack Version.

References


  del.icio.us it! digg it! reddit! technorati! yahoo!

SQL Server Reporting Services – Url Parameters in SharePoint Integrated Mode

SQL Server Reporting Services 2005 and 2008 added a new SharePoint Integration mode, which allows reports to be stored and managed in a SharePoint 2007 portal.  Data connection, reports, security, report subscriptions and notifications are all managed in SharePoint 2007. 

Advantages Of SharePoint Integrated Mode

In SharePoint Integration mode, reports can be rendered using Reporting Services web parts.  These web parts can be added to pages throughout your site.  You can link report web parts to filter web parts, to provide parameters to one or more reports on a page, which allows you to create Reporting Services dashboards.  You can even mix and match them with Excel Services charts, spreadsheets, and pivot tables on a single dashboard page.  Powerful stuff!!

RSViewerPage and the Report Viewer Web Part

When you configure Reporting Services to run in SharePoint Integration Mode, reports are displayed using the /_layouts/ReportServer/RSViewerPage.aspx page by default.  This page provides an a SharePoint look and feel, and integrated navigation back to your SharePoint site.  It leverages the Report Viewer Web Part to display the report.  The Report Viewer Web Part has some very nice features:

  • An integrated SharePoint look/feel
  • Cookie crumb navigation back to your site, MySite, and MyLinks
  • A collapsible parameter panel to the right of the report
  • A nice toolbar with zoom and page navigation
  • An Actions menu on the toolbar, allowing users to:
    • Export to various formats
    • Customize the report using Report Builder
    • Create report subscriptions

SSRSReportViewerWebPart

HTML Viewer in Native Mode and SharePoint Integrated Mode

When you configure Reporting Service to run in Native Mode, reports are displayed using an HTML Viewer interface that is built into Reporting Services.  The HTML Viewer provides all of the basic functionality users required to view, navigate, and print reports. It also provides many Url parameter options to control report parameters and rendering rendering – options that are not available when viewing reports using the RSViewerPage page and the Report Viewer Web Part.

Yes, You Can Use the HTML Viewer in SharePoint Integrated Mode
When you configure Reporting Services to run in SharePoint Integrated Mode, it’s your choice.  You can use either the RSViewerPage or the HTMLViewer to view your reports.  The look and feel of the HTML Viewer isn’t as nice as the RSViewerPage interface, but it’s equally functional, and it provides a lot of Url options that can’t be duplicated using the RSViewerPage.

SSRSHTMLtViewer

In the HTML Viewer, the report parameter options are displayed at the top of the page (the Report Viewer Web Part shows them on the right-hand side of the report).  You can use the HTML Viewer user interface to view the report, change parameters, collapse parameters, zoom, print, export, etc.  When you use the HTML Viewer to view your report, you lose the SharePoint UI look and feel, cookie crumb navigation, MySite and MyLinks integration, and Report Builder and Subscriptions integration.  You gain the Url options we’ll be discussing later in this post – options that are not supported by the RSViewerPage or the Report Viewer Web Part.

How To Display Reports Using the HTML Viewer Page

You still have the ability to call reports using the HTML Viewer page by providing a link to the ReportServer Virtual Directory with a full path to the rdl file, like so…

http://myrsserver/reportserver?http://portal/reports/reportslibrary/regional%20sales.rdl&rs:Command=Render

When you view your report in this manner, you are bypassing the SharePoint Integrated RSViewerPage.aspx page and the web part, and viewing the report using the native mode HTML Viewer.  The rs:Command=Render Url parameter instructs reporting services to display the report. 

Passing Report Parameters in the Url

When you provide a link to the HTML Viewer, you can use the parameter support in the HTML Viewer to control the display of the report.  Assume a report that accepts 3 parameters:

  • Region (integer)
  • StartDate (date)
  • EndDate

By adding Url parameters on the end of the HTML Viewer Url, you can easily pre-populate the report parameters for the user.

http://myrsserver/reportserver?http://portal/reports/sample%20reports/departmental%20sales.rdl&rs:Command=Render&region=2&startdate=9/16/2008&enddate=9/17/2008

As you can see, with this sort of report, you can provide a flexible report that can be used for multiple purposes.  You can easily swap out these links in code to insert the department and dates appropriate in the context of the application displaying the links.  Parameter values in the Url override default parameter values.

If all the parameters are supplied by Url or default parameter settings, the report is rendered automatically, without any further action required from the user.  Nice!!

Passing Report Rendering Instructions in the Url

Using the HTML Viewer, you can also control the rendering of the report.   You can set the rendering format (HTML, PDF, EXCEL, CSV, etc.), the zoom level, and a bookmark or default page displayed in the report. You can also toggle the appearance of toolbars, parameters, and the document map.  You can even provide default search criteria to display and modify the style sheet used to render the report, or set the report to display a specific page.

As an example, the following link will show the report at Whole Page zoom level, with parameters collapsed and document map displayed, with the last page displayed by default.

http://myrsserver/reportserver?http://portal/reports/sample%20reports/departmental%20sales.rdl&rs:Command=Render&rc:Zoom=Whole%20Page&rc:Parameters=collapsed&rc:DocMap=true&rc:Section=999

In the HTML Viewer, there are many options available that can be used to controlling report rendering.  This is a short list of the of the ones you’re likely to find useful:

  • rs:Format – Rendering modes you can pass are HTML3.2, HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, defaults to HTML4.0
  • rc:Zoom – Specified in percentages, supports Page%20Width and Whole%20Page, defaults to 100%
  • rc:Toolbar – True/False, used to show/hide the toolbar, defaults to true
  • rc:Parameters – True/False/Collapesed, used to show/hide/collapse the parameters in the toolbar, defaults to true
  • rc:DocMap – True/False, used to show/hide document map, defaults to true (not shown unless report has document map)
  • rc:Section – Specifies default page number to display, defaults to 1
  • rc:BookMarkID – Jumps to a specific bookmark in a report
  • rc:FindString – Provides search criteria to the report and finds the first instance of the string specified

Links For More Information

For more information on Url parameters available for the Reporting Services HTML Viewer and Report Viewer Web Part, check out these links:


  del.icio.us it! digg it! reddit! technorati! yahoo!