Monday, December 20, 2010

JSON, jQuery, IE, OData and a Parsererror

Quite a collection of technologies and approaches in that combination being used on a single page in SharePoint - mostly worked fine until I had deployed to a site using IE7. Suddenly my jQuery calls to $.getJSON() would silently fail, and with no error callback on the getJSON method, I resorted to an $.ajax call instead.

Experimenting in the error callback, found that even though the response status was success, there was an error - the error text was "parsererror". Seems that IE7's native parsing of JSON does behave too well for jQuery 1.4.2. Finally wrote some code in the error callback to detect when the err was parsererror, and in that instance to create a new JSON object using eval, similar to this:

type: 'GET',
url: serviceUrl,
contentType: 'application/json: charset=utf-8',
dataType: "json",
success: ProcessResults,
error: function (xhr, textStatus, errThrown) {
if (textStatus == 'parsererror') {
var json;
try { json = eval('(' + xhr.responseText + ')'); }
catch (e) { }

After working out this fix, I found some information on stackoverflow suggesting that IE has problems with leading new line characters at the start of the JSON in the HTTP response body.

Thursday, December 9, 2010

SharePoint Designer and generate-id

Just wanted to note down a great tip from Marc D Anderson (who derived the idea from a post by Jorge Vasquez) on how to work around the annoyance of SharePoint Designer 2007 inserting generate-id() statements into the ID attributes of HTML tags in customised XSL in SharePoint 2007 or WSS3 pages.

The small steps to applying this fix are as follows:
1. Create an empty dummy variable in the XSL , for example
<xsl:variable name="DummyVar">
2. Append this dummy parameter to any IDs, e.g.
<input id="myid{$DummyVar}" type=......

Thursday, October 14, 2010

WCF Data Service "Could not load file or assembly App_Web" Error

The "Could not load file or assembly App_Web_" error was showing sporadically on a small test WCF Data Service site.

In my first attempt to solve the issue, I deleted all files in the site, and copied the site files from a deployment package. The data service magically started working.

Later in the day, the same error returned. After researching on the web, came across one lead that suggested deleting all the ASP.Net temporary files. Other posts mentioned issues with compilation. Therefore, as an experiment I adjusted the Web.Config file of the site so that the Compilation node had the following attributes:

debug="false" batch="false"

And this seems to have solved the issue for me - I think each recycle of the Application Pool was causing an attempt to recompile, which was failing for some reason. Probably relates to the other post with regard to some issue around the ASP.Net temporary files folder.

Batch compilation isn't really necessary for this small app, so game over!

Sunday, October 10, 2010

Web Application with Host Header on Port 80 Fails

Adding new SharePoint web applications on port 80 is easy by associating a host header name, but I was unable to view the site collection in the new web application with IE - the login dialog box would show three times, and then just a blank page, even though my account was the primary site collection administrator.

Turns out that in Windows 2008 R2 it is necessary to disable the loopback check. Open the Powershell ISE or console (as administrator to get sufficient registry permissions!) and run the following script:

New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword

Thanks to Ignacio Montenegro of IGA Systems for that tip.

Thursday, September 30, 2010

Where's the "Configure Incoming Email Settings" Link?

If you cannot see the "Configure incoming e-mail settings" link in SharePoint 2010 central administration, and are sure you have all the permissions you require, try right-clicking on an IE icon and selecting "Run as administrator" from the context menu. In that instance of Internet Explorer, you may well see the link you are seeking!

Thursday, September 16, 2010

Access Denied for Configure Service Accounts Link

Clicking on the "Configure Service Accounts" link on a SharePoint 2010 server resulted in an "Access Denied" message.

Resolution of this issue is to run IE with Elevated Permissions by right clicking on an IE shortcut and selecting "Run as administrator"

Friday, September 3, 2010

At Last - Tame the Core CSS FIle!

Thanks to the blog of buta no le, I could solve that nasty issue of corev4.css being placed after my custom CSS file when using the SharePoint.CSSRegistration tag.

The reason I want to use that tag is that it allows the use of tokens to derive the actual site collection URL (as opposed to having to hard code the URL, and then editing the masterpage on the client site). In MOSS, SharePoint.CSSRegistration always places the core CSS file at the end of all the registered CSS files, thereby rendering useless any style overrides in your own files.

But SharePoint 2010 adds the "After" attribute to the tag. Nice! Now I can insert the following in the masterpage, and dictate my own styles over the core ones (note that the name actually needs to be enclosed in angle brackets!)

SharePoint:CSSRegistrationName="% $SPUrl:~sitecollection/style library/state.css
%" After="corev4.css" Runat="server"/>

Wednesday, September 1, 2010

Where is disco.exe?

Just been searching for this web service tool, so to save the effort of the hunt next time, here's the location of the folder holding the file:

C:\Program Files\Microsoft SDKs\Windows\V6.0A\Bin\disco.exe

Monday, August 30, 2010

PowerShell PS1 File Not Recognised as the Name of ....

Annoying wee behaviour - if calling a PowerShell file from a batch file, it seems that even if the BAT and PS1 files are in the same folder, and the BAT file has changed the current path to be that folder, it is still necessary to include the whole path to the PS1 file in the -command call.

The statements
cd [the folder path]
powershell -command "&{.\test.ps1}"
didn't work, whereas the following does work:
cd [the folder path]
powershell - command "&{[the folder path]\test.ps1}"

Tuesday, July 27, 2010

SP2010 - Get the Item ID from the OpenPopUpPage Link

Just wanted to record here a simple little jQuery script useful for retrieving the item ID from the OpenPopUpPage hyperlink that is rendered for lookup column values in a Data View Web Part in SharePoint 2010. The useful thing about this is that you can then manipulate the action of the hyperlink to pass this item id to a different page - without having to look at changing the field type in any way.

The lookup field is rendered in a DVWP with the following onclick action:

OpenPopUpPage( 'http://blah/_layouts/listform.aspx?PageType=4&ListId={FFFC7FEA-62B2-459F-9D1B-80B6CA3608FF}&ID=23&RootFolder=*', RefreshPage);

The XSL (in the DVWP) that is rendering this lookup value is as follows:

Trust Partner:

[An aside: "table-based HTML?" you may ask. Well, sometimes expedience wins over web standards, though I am usually a standards-based advocate!]

The jQuery script to extract and use the item ID is:

$(function() {
$('.linktoentitydetails').each(function() {
var $link = $(this).find('a');
var href = $link.attr('href');
if (href != '') {
var itemIdMatches = href.match(/.*&id=(\d+)&.+/i)
if (itemIdMatches.length == 2) {
var itemId = itemIdMatches[1];
$link.attr('href', 'persondetails.aspx?eid=' + itemId);

So, in this case, I am replacing the OpenPopUpPage hyperlink action with a simple link to a custom page (persondetails.aspx) on which I can present other information about this linked item.

Saturday, May 29, 2010

SharePoint Connection Error in Visual Studio 2010

When running Visual Studio 2010 on a Windows Server 2008 R2 / SQL Server 2008 / SharePoint 2010 development box, even though the logged-in account has local admin rights on the server, I still experienced a SharePoint Connection Error in Visual Studio 2010 on that same Virtual Machine. The text in the error dialog states that "the local SharePoint Server is not available".

Seems the error is caused be the logged-in account having insufficient rights against the SharePoint databases. Log into the SQL Server using the administrator account, and grant rights to the developer account; db_owner rights on the SharePoint configuration and admin database is reported to be sufficient -but as in this instance I was dealing with a development virtual machine, I opted for the easy route of granting sysadmin role to the dev user account :-)

Thursday, May 6, 2010

SPServices Error With GetListItems Call

If you get an error similar to "Guid should contain 32 digits with 4 dashes" when making an SPServices Web Service call to the GetListItems operation, check the premissions on the list you are querying - I got this error returned from the call, and found that the list permissions were set so that the current user did not have read permissions.

Granting read access to the user instantly removed the issue :)

Wednesday, March 17, 2010

SharePoint Error for One User - The File Exists

Today had an interesting support issue to investigate. Of all the users on a SharePoint intranet, one person was unable to upload documents - each attempt to upload a document to a document library resulted in the "Access Denied" page. And the ULS log revealed little of value even in verbose mode.

The other strange thing was that this user is configured as the site collection owner, and was able to create document libraries fine. But then could not add a document to the document library he had just created!

Finally got some clues when I removed that account from the site owner SharePoint group (just in case that group was causing the behaviour). When I tried to add the account back to that group, an error page displayed with the useful(?) message "The file exists (Exception from HRESULT: 0x80070050)". At least that helped to confirm that the issue was in the user account.

A bit of research revealed this post on the subject - seems likely that the SID for the account has changed at some point. The described fix is to modify the SID in one of the SharePoint database tables. That's a bit of a worry, given that fiddling with the database content is like confusing a Kiwi accent for an Australian - to be avoided. But it may be the only approach available. Let me know if you try it out and it works for ya.

Tuesday, March 2, 2010

Roadblocks in the Install of Server 2008 R2 and SharePoint 2010 Beta

First up in my path to getting SharePoint 2010 running in a Hyper-V VM was the case of the missing roles in Windows Server 2008 R2, caused by a Windows update that failed to install.

For some unpleasant reason, KB971468 had failed to install correctly, following the cancellation of the install of KB890830 (the windows update panel had stopped mid-install, and the progress bar just stayed where it was). The outcome of this was that no roles displayed in the Server Manager - instead just an error message.

With the help of some worried searching, I came across this article by Glafkos Charalambous explaining the fix - use the System Update Readiness Tool from Microsoft to discover the faulty update files, then manually extract those files from the relevant update packages and copy them to the updates folder.

Once I had replaced the bad MUM files (wonder if there are DAD files anywhere in the system, too??), then I couls rerun the other updates that were marked as failed in the Windows Update History.

Hey, honey, I got my roles back!