Tuesday, January 17, 2012

HTML5 Learnings - Getting IE9 to Accept Canvas Elements

Working with HTML5 at the moment is a lot like the "good old days" of designing pages to work in IE, then redoing the page for Navigator (oooh, showing my age in the industry there!)

Anyhows, today's little lesson was about a small subtly in IE9 behaviour when handling a page incorporating Canvas elements. Initial I was working on the page in Web Expression, and viewing the page via a "file://..." path in the IE9 address bar. All was fine, and the JavaScript rendering the canvas element content worked OK.

But then I copied the HTML into a page being served up through IIS, and accessed via an "http://..." address. Looking at this new page, IE9 now tells me that the canvas element is not supported (modernizr adding the "no-canvas" class to the html element). Weird. Much playing later, found that it is necessary to add the following header metatag to the page:

<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

Seems that IE treats pages accessed from the file-system differently that those from an http address!

Wednesday, January 4, 2012

Setting BCS Secondary Fields Programmatically in SharePoint 2010

Phew, that was quite a battle. I have been writing some code to import values from a CSV file into some custom lists in SharePoint (I realise that there are, of course, plenty of other ways to import into SharePoint, such as using PowerShell or a third party app., but specific needs call for special handling), and one of the requirements is to import data into External Columns in the SharePoint list.

Original this process used the GetSecondaryFieldNames() method of the SPBusinessDataField instance to get the internal names of each of the secondary fields, and then combined each of those with the internal name of the SPBusinessDataField to create the displayname value for each secondary field. The list item fields could then be set using these displayname values.

This worked fine in the dev environment... but of course the real workd is different! Researching the failure of this process on the target machine showed that the display names for the secondary fields did not contain the values from the GetSecondaryFieldNames() call (PowerShell allowed me to easily view the Schema XML for the fields in the list, saving the need for a tool like SharePoint Manager).

So, my solution was to seek the secondary field by enumerating through all fields in the list, seeking the field whose:
  • "DisplayName" property value starts with the internal name of the related external data field
  • "BdcField" property value matches a string value returned by GetSecondaryFieldNames()
This lets me find the required secondary BCS field, and gived me the GUID for use in later populating that field with a value. I then make sure to cache this GUID, meaning on the next pass through this part of the code I can use the cached value rather than re-enumerating all the fields once again.

Tuesday, October 25, 2011

FileNotFoundException with "new SPSite" Call

This one came back to bite me again, so time to note it down here - when running any test code which accesses a SharePoint web or site using new SPSite(url) in a console application, or in a Visual Studio 2010 test project, it is necessary to adjust the build properties of the project.

The project build configuration (the second tab down in the project properties) need to have the Platform Target explicitly set to x64. If this target is set to x86, or possibly to "Any CPU" then the call to "new SPSite" will fail with "FileNotFoundException", stating that "The web application cannot be found". Next time I'll remember...

Wednesday, October 19, 2011

Error in Visual Studio 2010 Packaging a SharePoint 2010 Solution

Was getting an error stating that a file "deploys to the same package location" when packaging a SharePoint 2010 solution in VIsual Studio 2010.

Turns out that the SharePointProjectItem.spdata file (in the module subfolder within the Visual Studio project) had somehow gained duplicate entries for a particular file.
To fix this,
  1. Unload the project in VS (or close the entire solution)
  2. Find the SharePointProjectItem.spdata file in Windows Explorer, and edit in Notepad++ (or your favourite text editor!) to remove the duplicate reference
  3. Reload the project in VS, and select that "Package" action - all then worked for me.

Thursday, September 29, 2011

Cannot Log in with Microsoft Lync

Took a while to track this one down - a fresh install of Lync refused to connect or login to Office 365. Experimented with adjusting the manual configuration settings as suggested by lots of posts, but to no avail. Finally found a comment on a forum suggesting to check the time on the computer. The time was in fact a few minutes fast - so I set the time, restarted Lync, and login worked straight away. Who'd have thought?!

Tuesday, September 13, 2011

Cant Seem to Remove Columns from a Content Type in a Solution

Some behaviours in SharePoint 2010 solutions have become frustrating compared with SharePoint 2007 solutions. One that's particularly troublesome is attempting to modify site columns in a custom content type that inherits from a non-built in content type.

When inheriting from a publishing article page content type using a solution,  just can't seem to remove a couple of site column. Neither of the following approaches seems to work. If I come up with a solution, I'll add it hear.

            <FieldRef ID="{d3429cc9-adc4-439b-84a8-5679070f84cb}" Name="ArticleByLine" Hidden="TRUE" />

            <RemoveFieldRef ID="{d3429cc9-adc4-439b-84a8-5679070f84cb}" Name="ArticleByLine" />

Shrinking the SharePoint Log FIle (for dev machines)

Found some useful information on taming a large log file - useful on a SharePoint development machine.

To shrink log files in sql server 2008, first change the recovery model of database to simple, then shrink the log file and finally change back to the previous recovery model. Here is the SQL:

USE dbname;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE dbname
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (2, 1); -- here 2 is the file ID for trasaction log file,you can also mention the log file name (dbname_log)
GO
-- Reset the database recovery model.
ALTER DATABASE dbname
SET RECOVERY FULL;
GO
 
Thanks to an answer by RTTAdmin on the MSDN forums for that suggestion.