Categories
SharePoint

Using the Content Query web part in SharePoint without activating the Publishing feature

You can use the Content Query web part within a SharePoint site without activating publishing feature (which you may want to do as activating the feature introduces and changes a lot of options):

  1. Go to the Web Part Gallery within an existing publishing site
  2. Export the ContentQuery.webpart file and upload it to the Web Part Gallery of the destination site
  3. Copy the three .XSL documents (Header, ItemStyle, ContentQueryMain) from the XSL Style Sheets folder within the Style Library and transfer them to the destination site
Categories
SharePoint

SharePoint 2013 & PerformancePoint

Note to self: Instead of banging your head for two days trying to resolve the issue of PerformancePoint reports not displaying. When you see a “Failed to Sql Query data XEvent collector on sqldbserver…” message within the log files, first ensure that the SharePoint farm account has been granted the serveradmin role upon the SQL server.

See: Failed to Sql Query data XEvent collector on sqldbserver. The error is Object reference not set to an instance of an object. And other SQL related errors in SharePoint 2013

Categories
WordPress

Identifying Custom Templates in WordPress

Sometimes, particularly when you’ve taken over the development of an existing WordPress-based website, its handy to be able to tell which of the custom templates in the theme folder are actively in use and by which pages. The following SQL query gives you that information.

SELECT p.ID, p.post_title AS Page, p.post_status AS Status, m.meta_value AS Template
FROM wp_posts p
LEFT JOIN wp_postmeta m ON p.ID = m.post_id
WHERE m.meta_key = '_wp_page_template'
ORDER BY p.post_title
Categories
Databases

Kill All Active Database Connections

USE Master

ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE 

ALTER DATABASE YourDatabase SET MULTI_USER

See Kill All Active Connections To A Database

Categories
SharePoint

SharePoint’s People Picker Error

Since the roll out of Internet Explorer 10, our users were having trouble whenever they attempted to give someone access to their SharePoint 2010 area via the Grant Permissions dialog. Whenever they clicked the Browse icon, they’d receive a “An unexpected error has occurred” message.

One solution that seemed to solve this issue was to add the domain of the SharePoint site into the browser’s Compatibility View Settings – but that would effect all sites using the domain (including non-SharePoint sites).

While researching the issue I found a suggestion that it could be corrected by appending a META tag to one of the MasterPages.

Normally I wouldn’t dare edit one of the SharePoint core files, but as this was effecting so many users and we’ll be migrating to SharePoint 2013 in the near future, the benefits outweighed the risks.

  1. Browse to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS and locate the pickerdialog.master file.
  2. Immediately after the opening HEAD tag, insert the following line: <meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE8″ />

The changes appear to have resolved the issue completely.

Categories
WordPress

Hiding Disqus Comments

While the Disqus commenting system may be fine for standard post types, sometimes clients don’t wish to use them on specific custom post types. Previously (c. 2013), the following code worked for me…

add_filter( 'the_content' , 'dsq_comments_template_remove' );

function dsq_comments_template_remove( $content ) {
	global $post;

	if ( function_exists( 'dsq_comments_template' ) && 'post' != get_post_type( $post ) ) {
		remove_filter( 'comments_template', 'dsq_comments_template' );
	}
	
	return $content;
}

Now I have to use this code:

add_filter( 'comments_template' , 'dsq_comments_template_remove', 1 );

function dsq_comments_template_remove( $file ) {
	if ( 'question' == get_post_type() ) {
		remove_filter( 'comments_template', 'dsq_comments_template' );
	}

	return $file; 
}

Source: How to Disable Disqus on Custom Post Types in WordPress

Categories
Coding

Value does not fall within the expected range

The following code, which was supposed to update the “Current” Composed Look, was throwing a “value does not fall within the expected range” error each time I ran it.

SPWeb web = properties.Feature.Parent as SPWeb;
SPList gallery = web.GetCatalog(SPListTemplateType.DesignCatalog);

if (gallery != null)
{
    SPQuery q = new SPQuery();
    q.RowLimit = 1;
    q.Query = "<Where><Eq><FieldRef Name='DisplayOrder'/><Value Type='Number'>0</Value></Eq></Where>";
    q.ViewFields = "<FieldRef Name='DisplayOrder'/>";
    q.ViewFieldsOnly = true;

    SPListItemCollection items = gallery.GetItems(q);

    foreach (SPListItem item in items)
    {
        item["MasterPageUrl"] = web.MasterUrl;
        item.Update();
    }

}

After a lot of head scratching, it boiled down to the ViewFieldsOnly property which, which I had left set to true. Doh! Updating the property to false corrected the error.

See: SPQuery.ViewFieldsOnly property

Categories
SharePoint

The URL is not available, does not reference a SharePoint site, or you do not have permission to connect

This is a handy thing to remember for an issue I just ran into. When you try to connect to a SharePoint URL from Dashboard Designer, you may see the following prompt:

“The URL is not available, does not reference a SharePoint site, or you do not have permission to connect”

To resolve the issue I had to ensure that the Service Account which was running PerformancePoint Services had been given owner-level access to the Content database.

Categories
SharePoint

SharePoint Content Type IDs

This is a handy PowerShell snippet for returning a list of all Content Types and their IDs within a SharePoint site.

$site = Get-SPSite http://www.domain.com
$web = $site.RootWeb
ForEach( $contentType in $web.ContentTypes ) { Write-Host $contentType.Name": "$contentType.ID }
Categories
Databases

MS SQL and MD5

SQL Server doesn’t appear to have a nice MD5 function like MySQL does (shame), but there is still a way to do it.

DECLARE @value VARCHAR(255)
SET @value = "This is an MD5 encoded string'
SELECT SUBSTRING(sys.fn_sqlvarbasetostr(HASHBYTES('MD5', @value)), 3, 32)

This was useful for resetting the admin password within an instance of Moodle that had recently been migrated to SQL Server.

UPDATE [moodle].[dbo].[mdl_user] SET [password] = SUBSTRING(sys.fn_sqlvarbasetostr(HASHBYTES('MD5', 'newpassword')), 3, 32) WHERE [username] = 'admin'