Sunday, March 18, 2012

Force Post in .load method

The following code:
$('div').load('Service.asmx/HelloWorld')
may produce the error in the Response as visible from the Console tab of Firebug: "Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'."

This ASP.NET web service expects a POST. To force a POST change the code by adding a bogus object to the .load jQuery method:
$('div').load('Service.asmx/HelloWorld',{test:"blah"})

Update: Actual fix is to edit the web.config, see comment by Lotas here.

Monday, March 12, 2012

Setting Theme in Feature Receiver

When provisioning web sites, the theme was not taking. To get it working I made the following change to RestoreWebProperties, which was generated by SharePoint Solution Generator.

string key = xWebProperty.Attributes["Key"].Value;
string value = xWebProperty.Attributes["Value"].Value;
//this does not work for __IncludeSubSitesInNavigation, use AllProperties instead
/* if (web.Properties.ContainsKey(key))
{
web.Properties[key] = value;
}
else
{
web.Properties.Add(key, value);
} */
//need explicit set, apparently setting via property bag does not effect update
if (key == "vti_themedefault")
{
try
{
web.ApplyTheme(value);
}
catch { }

}
else
{
web.AllProperties[key] = value;

}



Note, get the theme key from TemplateID element in SPTHEMES.XML. Also do web.Update() instead of web.Properties.Update().

Friday, March 9, 2012

TFS Project Folders and Workspaces

In Source Control Explorer, one way to map separate folders to separate local paths, perhaps on a separate drive e.g., is to use Workspaces.

Do File, Source Control, Workspaces, Add Workspace. Name the Workspace as appropriate, e.g. "My Projects." Select the TFS project folder, and the corresponding Local folder. Click OK.

This way you can separate your local files on a separate local root folder, (e.g. c:\My Projects") from folders other team members own (e.g. mapping of c:\Other projects).

Sunday, February 26, 2012

Perl Map Chaining to Obtain Unique Subkeys

Say you have a file with contents:

AABB 7323|Jan 28, 2003|Random Data Here
YZZ 2852|Mar 3, 2007|Data Data
YZZ 2559|Aug 2, 2010|More Data
AABB 2383|Jun 1, 2011|Data Field Data

The following perl script can list the unique key types:

#!/usr/bin/perl

use strict;
use warnings;

my $filename = "testinput.txt";
open (ROWS, "<$filename");

my $delimiter = '\|';

my %values = map {split / /, $_ } keys %{{map { split $delimiter, $_, 2 } <ROWS>}};
my @uniques = keys %values;
print join ("\n", @uniques);

exit 0;

which outputs:

AABB
YZZ

Note: when assign an array to a hash lvalue, the array elements are assign sequentially in key value pairs, since there's no such thing as hash context. see http://tutorials.freeskills.com/professional-perl-part-3-prototypes.htm

Tuesday, February 14, 2012

Master Pages in Subsites

You may get "The system master page setting currently applied to this site is invalid. Please select a new master page and apply it" in _layouts/ChangeSiteMasterPage.aspx, when having set a subsite of a site collection (with publishing infrastructure enabled) to use a master page within the subsite relative _catalogs/masterpage/ folder. It appears MOSS 2007 publishing infrastructure does not fully support subsites utilizing master pages from subsite master page galleries, hence the error.


To avoid this error, ensure that every subsite in a site collection with Publishing Infrastructure enabled is using a master page that resides in the master page gallery of the root site.

Ironically, doing so however, causes another error in SharePoint Designer "The URL ../../_catalogs/masterpage is invalid" when editing the subsite in SPD. Therefore, it appears that editing subsites in site collections, that have Publishing Infrastructure enabled, in SPD is not supported.

Monday, February 13, 2012

Setting Default DisplayCategory for Create Site Page

In MOSS 2007, one way to have your template category selected by default when click "Create Site" from Site Actions when Office SharePoint Server Publishing is enabled is edit 12\TEMPLATE\LAYOUTS\EditingMenu\SiteAction.xml (Backup first!). Edit the ConsoleNode item whose action is "cms:CreateNewSiteAction" and ID is "wsaCreateSite." Add (or replace) two attributes:
IsSiteRelative="true"
NavigateUrl="_layouts/newsbweb.aspx?DisplayCategory=MyCustomTemplates"

Note, the IsSiteRelative attribute is required so that subsites don't get file not found errors.

Finally, recycle the app pool.

Another option that applies to site collections only is to edit _catalogs\masterpage\Editing Menu\CustomSiteAction.xml, adding the Console tags with custom content as needed.

Tuesday, February 7, 2012

Publishing Enabled on Root Site

I noticed that unless Office SharePoint Server Publishing is enabled on the root site in a site collection, subsites do not show the Pages Library as a "List Type" in the Content Query Tool Part, regardless of whether Publishing is enabled as site feature in the subsite.

I have not done exhaustive testing to see whether this is related to the initial site definition that was applied, but at any rate, this appears to be a bug (or "gotcha") in MOSS 2007.