Stefan Goßner

Senior Escalation Engineer for SharePoint (WSS, SPS, MOSS, SP2010) and MCMS

Code Samples

Code Samples

  • Comments 9
  • Likes

As some of you already noticed: GotDotNet is now down and the code samples previously hosted there have been migrated to the MSDN code gallery.

For your convenience here are links to all my code samples:

SharePoint 
  • CDInfo
    This tool allows to gather information about the configuration of content deployment in a farm.
    That includes the content deployment general settings, all configured paths and jobs, and for all the jobs all deployment reports that were generated.
     
  • FixPageLayout
    When moving a database with backup/restore between different web farms the URL from the Publishing Pages to the PageLayout often contains the server name of the original farm.
    That can lead to exceptions. Details can be found here:
    http://blogs.technet.com/stefan_gossner/archive/2008/03/12/common-error-situation-with-when-using-backup-restore-to-transfer-a-database-to-a-new-farm-on-moss-2007.aspx
    This tool allows to correct this problem.
     
  • PublishingPageContainer
    SharePoint master pages are used as well for PublishingPages in the Pages library and for the DispForm.aspx and EditForm.aspx pages in the Forms folder of the Pages library. As these pages are not PublishingPage objects certain controls generate exceptions when included on the master page.
    The PublishingPageContainer ensures that it's child controls are removed if the current page is not a PublishingPage.
     
  • VaryByUser
    SharePoint does not allow to cache a different version of a page per user.
    Caching per user is for sure not something you would like to implement on every page of your site. But often there are certain pages which should be rendered differently for different users - either because the users can customize the page to their needs or the page contains information about the user like an address or account details. 
     
  • WssAnalyzeFeatures
    This tool allows to verify if the feature definition files for all installed features are present on the file system. Also allows to verify if the features used in site collections an sites are installed on the server. In addition it can create a checklist file which can be used to verify if a server has all features installed required to act as destination for a content deployment job of an existing sitecollection.
     
  • WssRemoveFeatureFromSite
    In some situation the STSADM command STSADM.EXE -o deactivatefeature is not able to deactivate a feature either on site collection or on site level.
    This can (e.g.) happen if the feature definition for the feature that has to be removed is not installed in the farm.
    This tool allows to remove the feature from the site or site collection completly.
     
  • XmlCleanupSoapExtension
    .NET webservices use XML 1.0 in SOAP responses. XML 1.0 does not allow certain characters like vertical tab. This can lead to exceptions when serializing objects as return values for web services.
    This SoapExtension allows to clean the XML before the content is sent over the wire.

MCMS

  • Add WYSIWYG to the HtmlPlaceholderControl
    The HtmlPlaceholderControl shipped with CMS 2002 does not provide WYSIWYG. This means while editing the style added to the template are not applied to the content. The attached placeholder control will add this feature. It does only support styles added by external CSS files not styles added directly within style tags.
     
  • Adding Placeholder Controls Dynamically
    Template without an HtmlPlaceholder control included. The HtmlPlaceholder control will be added dynamically in the Page_Load event. Can be modified to allow dynamic number of placeholder controls per page.
     
  • ASP.NET 2.0 MembershipProvider Framework for MCMS
    This framwork allows easy development of MembershipProviders for MCMS. See here for more details.
     
  • calling SDAPI from managed Code
    These are two samples to use SDAPI from managed Code. To build these two console applications you need to add a reference to the following server-side SDAPI dll. To do this select the following DLL from the list of COM based DLL's in the Reference Dialog: "MSCMS Site Deployment (Server-side)"
     
  • Class to Manage custom channel properties
    This sample implements an workaround for the fact that there is no API to create custom channel properties using PAPI.
     
  • Client-Side validated Placeholder Control with enhanced Console Actions
    This is a sample placeholder control which allows content validation. It is required that you also replace the standard ReeditSaveAction, SaveNewAction and ReeditSaveAndExitAction with the version included in this sample to ensure that the validation is fired on save.
     
  • CmsSslHttpModule
    This HttpModule makes it easy to SSL enable parts of a MCMS Web site. It manages switching between SSL and http for dedicated channels. No additional coding in the template project is required. Just integrated this http module and set the RequireSSL custom channel property to "yes". The rest will be handled by the http module.
     
  • Console Action "Create New Page" with DefaultTemplateGallery attribute
    This Console Extension can be used to replace the standard "Create New Page" Action. It will check the current channel for the DefaultTemplateGallery attribute and open the Template Gallery Explorer at the defined gallery if defined.
     
  • Console Action "Decline with Reason"
    This console extension adds a new dialog to the decline action to ask for a reason when doing a decline action. The input is added to the data sent to the server and can be evaluated in the workflow event by reading Request.Form["DeclineReason"];
     
  • Console Action to create a "shadow" posting on request
    This is a "proof-of-concept" and not a ready to use solution to show how to implement a ConsoleAction to do updates on the server when Webauthor is in unpublished mode. It shows how to implement the redirect to update mode to ensure that the update can be done and the additional redirect to unpublished mode. I would recommend this sample to everyone who is interested in developing this kind of Console Extensions.
     
  • Console Action: Save&Exit with ReleaseOwnership
    These Console Actions call ReleaseOwnership after each save to ensure that every Author is able to edit a Posting. Otherwise the Posting is locked until the Author submits his changes. This version also contains action for Save New and Save (without Exit)
     
  • Corrected Image and Attachment Placeholder Controls
    The SingleImagePlaceholderControl and SingleAttachmentPlaceholderControl have a small bug: they render a link to an image named transparent.jpg in the current directory.
    As this is only a cosmetic bug that causes 404 errors in the IIS log this bug will not be fixed in a hotfix. As this is still an anoying problem for some users I have implemented two custom placeholder controls derived from the original placeholder controls which fix the problem.
     
  • Create a template definition programmatically including placeholder definitions
    An often requested feature is to create a template definition programmatically (e.g. to replace the MCMS Template Explorer). This includes adding of placeholder definitions and custom property definitions to the template definition. This sample demonstrates how this can be achieved.
     
  • Date Picker / Calendar Placeholder Control
    This is a placeholder control based on the Calendar Control which allows the author to pick a date and store it it in the placeholder object.
     
  • DLL Version of Tool to get resource dependencies
    MCMS does not provide a mechanism to identify if a resource gallery item is currently being used by a posting or not. This DLL closes this gap by allowing to get a collection creating a report for all resource gallery items showing all postings pointing to a specific resource.
     
  • DropDownListPlaceholderControl
    This PlaceholderControl allows the author to select a specified value from a DropDownList.
     
  • Enhanced authorization module for MCMS
    The CmsAuthorizationModule shipped with MCMS does not work properly when using a MCMS posting as login page. This module can be used as replacement for the out-of-the-box control and solves this problem.
     
  • Enhanced Version of RobotMetaTag Server control that also works in Channel Rendering scripts
    Enhanced Version of RobotMetaTag Server control that also works in Channel Rendering Scripts. The version shipped with MCMS only works in Postings
     
  • Export Resource Galleries using SDAPI
    This sample demonstrates how to export resource galleries using SDAPI. SDAPI does not allow to do this directly so a helper posting is generated that gets links to all resource gallery items. After the export is done the helper posting is deleted. To import it either use normal methods or extend your import script to remove the helper posting also on the production machine.
     
  • FAQPlaceholderControl
    This sample placeholder control demonstrates how to extend the standard HtmlPlaceholderControl in authoring mode with new functionality. On button click it inserts a preformatted table to easily create FAQ pages.
     
  • Hidden Html Placeholder Control
    Html Placeholder Control which is only visible in unpublished and authoring mode. Good for side notes and hints to authors or editors which should not show up on the live site
     
  • Hideable Html Placeholder Control
    Using the hidden attribute of a HtmlPlaceholder control or hiding a placeholder control though other methods like inline code in the template file causes problems in authoring mode (e.g. loosing content in hidden controls). This placeholder control exposes its own property to hide and show and also preserves the content when hidden in authoring mode.
     
  • HttpModule to allow usage of PostBackUrl property with MCMS and ASP.NET 2.0
    ASP.NET 2.0 introduces a new feature to allow cross-Postbacks to other webforms using the PostBackUrl property.
     
    This method is very nice and allows to replace ugly workaround that were required in ASP.NET 1.x like using GET requests with query strings or adding client side script that cleared the viewstate form field.
     
    There is only one caveat with this new method: It does not work with MCMS 2002. MCMS 2002 Service Pack 2 which is required to allow MCMS to work with ASP.NET 2.0 adds some additional client side javascript code that prevents the PostBackUrl property from working properly as it always changes the Url back to the MCMS template file. So the logic of this client side script does not handle the cross-Postback situation correct.
     
    This http module allows to resolve the problem.
    See here for details.
     
  • HttpModule to avoid the ugly URLs being caused by postback calls
    When postbacks happen by switching from edit mode to live mode or being caused by ASP.NET controls the URL in a browser will become an ugly string. This HttpModule solves this. Details see here.
    Last updated based on the infos here.
     
  • HttpModule to avoid the ugly URLs being caused by postback calls (ASP.NET 2.0 version)
    When postbacks happen by switching from edit mode to live mode or being caused by ASP.NET controls the URL in a browser will become an ugly string. This is the ASP.NET 2.0 version of the HttpModule that solves this. Details see here.
     
  • HttpModule to enforce compatibilty between MCMS and ASP.NET 2.0 in Authoring Mode
    ASP.NET 2.0 generates different html code as ASP.NET 1.1. The Javascript code from MCMS is not compatible with the new format. This http module adjusts the the html to work with MCMS 2002 SP1a.
    See here for more details.
     
  • HttpModule to enforce compatibilty between MCMS and ASP.NET 2.0 Themes
    Stylessheets for ASP.NET 2.0 themes are registered using a relative path. This HttpModule corrects this problem. More details here.  
     
  • IE ActiveX Behavior Change solution for MCMS
    Newer versions of IE do no longer autoactivate ActiveX controls. To overcome this limitation I have created this custom HtmlPlaceholderControl which does not suffer from this problem.
    Details here.
     
  • Image placeholder control with align property
    This placeholder control does the same as the standard image placeholder control but it allows alignment of the placeholder control based on a control property.
     
  • ImageChangePlaceholderControl
    This placeholder control demonstrates how to utilize the Resource Gallery and Hyperlink Dialogs the placeholder controls shipped with CMS are using. It replaces the image in an onmouseover and onmouseout action. In authoring mode it allows the user to select both images and the hyperlink destination if required.
     
  • MCMS Site Map Provider for ASP.NET 2.0
    Sample provider which can be used with the ASP.NET 2.0 navigation controls to implement site navigation with MCMS.
    Details see here.
    Updated version is here.
     
  • MultiAttachmentPlaceholderControl
    This sample demonstrates how to utilize the methods to access the Resource Gallery as done by the placeholder controls shipped with MCMS. It implements a placeholder control which can hold multiple attachments similar to the SingleImagePlaceholderControl shipped with MCMS.
     
  • PDF Placeholder Control
    Placeholder Control to demonstrate how to integrated PDF Content in Cms Postings
     
  • Placeholder Control to store all kind of Html tags
    Sample placeholder control that allows to store all kind of tags including Javascript code, Object tags, IFRAMES, ... in a MCMS placeholder.
     
  • Plain Text Placeholder Control
    This sample demonstrates how to utilize a TextBox control as client side editor. This can be interesting in environments where no ActiveX controls can be used.
     
  • Populate a default content to a html placeholder control
    Sometimes it is necessary to define a default value for a html placeholder control and giving this default value using the description property of the placeholder definition is not sufficient (e.g. because the content should come from a database). This sample demonstrates how to define a custom placeholder controls that defines a default value. You only have to add the logic to define where the default value needs to come from.
     
  • Property Authoring Server Control
    A common question I received from customers is that they would like to edit property values during authoring time similar to editing placeholder content. This server control provides the solution for this. Here is an article with more details.
     
  • Random Image Placeholder Control
    Display a random image from a resource gallery the author configured. Non-Image items in the resource gallery will be ignored.
     
  • Render Channel
    This is a channel rendering script that demonstrates how to list the content of a channel using a Grid Control and a Repeater Control.
     
  • RenderPlaceholderServerControl
    This is a server control that behaves like a Placeholder in presentation mode. But it renders a Placeholder on a different posting! This can be used an a summary page or for common text (like legal notes or copyright) which need to be included on many postings. Supported Placeholders: HtmlPlaceholder, ImagePlaceholder and AttachmentPlaceholder (including generated Icon) and the Office variants.
     
  • Revert page to previous Version
    Console Extension to revert a posting to a previous version.
     
  • RSS aggregator placeholder control
    This is a custom placeholder control for MCMS which can be used to display information published in an RSS feed somewhere in the internet on a MCMS Web site. Has several parameters to configure the feed. Also contains a css file which should be embedded into the template to get it displayed nicely.
     
  • Sample to show how to modify the MCMS 2002 Edit Toolbar
    This sample adds additional buttons to align an image in an HtmlPlaceholderControl
     
  • Save new Page without Name prompt
    An often requested feature is a console extension which allows to save a page without being prompted for a name (e.g. the name should be generated by a business rule).
     
  • Script to Bulk Upload of files to a Resource Gallery
    This sample shows how to upload all files in a directory to a Resource Gallery by code. Much quicker as drag and drop to Site Manager.
     
  • Script to return all expired postings in the CMS repository
    This Script will list all expired postings in the CMS repository
     
  • Select Button Placeholder Control
    This is a sample to implement a CheckBoxPlaceholderControl to store bool values in convenient form.
     
  • Server Side Image Resize for Display
    This Webform can be used to resize images in a MCMS resource gallery before they are sent to the client. This can be used as a dynamic thumbnail generator. This webform opens the resource image as file stream, resizes it and sends the new image back to the browser.
     
  • Shockwave Flash Placeholder Control
    Sample Placeholder Control for Shockwave Flash Movies. It uses an Attachment Placeholder to hold the Link to the Shockwave Flash Movie. Width and Height can be defined at template level but might be overridden in the AttachmentText property. Format (x,y).
     
  • SiteStager for ASP.NET and ASP based templates
    MCMS 2002 does not allow to create a static copy of a MCMS Web site with ASP.NET based templates. Creating static copies is often very useful – e.g. when you create a CHM file based on your web site content or if you would like to archive a snapshot of the website at a specific time for documentation. The recommended method to create a static copy of a MCMS web site is to use a 3rd party web crawling tool. The problem with such tools is that they usually fail to work when the links between the posting are not rendered as html link but (e.g.) created with client side XML/XSL or JavaScript. This tool does not have this limitation.
     
  • Stripping HtmlPlaceholderControl
    Stripping HtmlPlaceholder control. It will remove unwanted tags from a HtmlPlaceholder. You could adjust this to your needs. The current version removes the Office XML tags and all font formatting information to allow stylesheets to apply correctly.
     
  • Tool to get dependency reports for resource gallery items
    MCMS does not provide a mechanism to identify if a resource gallery item is currently being used by a posting or not. This tool closes this gap by creating a report for all resource gallery items showing all postings pointing to a specific resource.
     
  • Webauthor Extension for paging and sorting of tree and list views in standard dialogs
    I've often received requests from customers whether the tree view or list view elements can be sorted by default. And whether the default for the number of items being displayed can be changed as the default number of five items is not very comfortable. This solution addresses this. Additional information in the included Word document. Update: March. 02, 2005 - added sorting for postings in hyperlink dialog. I missed this in previous release.
 
Comments
  • As some of you already noticed: GotDotNet is now down and the code samples previously hosted there have

  • Do you still have the sample code for "Solution to allow property editing when being in authoring mode"  

    This sounded like a spot on piece of code and very useful, but can no longer get hold of it!

  • Hi David,

    sure! Check the list above. It is named "Property Authoring Server Control".

    Cheers,

    Stefan

  • Do you have any code or examples wherein I can write a console application that will extract sharepoint list data to my own (custom) sql table? I thought of doing this and putting in a batch so that it run every midnight.

    Thanks a lot.

  • Hi PJ,

    no I don't have such sample code.

    Cheers,

    Stefan

  • Hello Stefan,

    is there a way to support overriding application settings in channels? (just like overriding the root-web.config in a folder).

  • Hi David,

    what is an "application setting"?

    Can you give an example?

    Cheers,

    Stefan

  • Hi Stefan,

    I mean a configuration value in the web.config. What I need is to override a specific value for all pages shown in one channel.

    In a CMS-less web application I would simply place a second web.config into the folder containing the pages. Can I do something similiar with a channel? Did I make my point clear? Thank you for your help!

    Greetings,

    David

  • Hi David,

    what you would need to do is to create the virtual directory structure representing the same URL as the channel in IIS and then place the web.config there.

    That should do the job.

    Cheers,

    Stefan

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
Raw Html Fix