Monday, 7 February 2011

SP2010 Coding Tips

Retrieving a list using the Serve-side Object Model
*******************************************
Problem:  In MOSS we could use CAML queries or the SharePoint API (Server side object model) to retrieve list data.  In SP2010 there are various methods for getting a list however, the Server-side Object Model has been improved/enhanceced.

SPSite site = new SPSite("http://demo.dev");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Customers"];

Hypothesis:
If the list doesn't exist you received a NullReferenceException.  A try catch block is usually wrapped around the list retrieval however, SP2010 has an improved method TryGetList().

Resolution:
SPList list = web.TryGetLists["Customers"];  // if list doesn't exist list will be null.
Other improvements to the API include: TryGetFieldByStaticName,

Disposing Objects
***************
Problem: SPSite and SPWeb objects are not automatically disposed.
Resolution:  Use either using statements or try catch finally statements to dispose of SPWeb and SPSite objects.  Check all code using the SPDisposal tool.

More Info:
Reading this post jogged my thoughts on the 2 topics posted above.  This is useful for SP developers to know.

Saturday, 5 February 2011

What version of SharePoint do I have? Common mistake!

Problem: You have a SharePoint web site and you have no idea what version is running.

Initial Hypthesis: Using Central Admin (CA) you can lookup the exact version.  However, if you are looking ata  website or don't have CA access, a lot of people think they can look at the http header.  (You can see the https header using fiddler or the IE developer tools).  However, the http header with the version number is not the actual version installed.  It is the version when the SharePoint install was performed!
This behaviour applied to MOSS and I have no idea if it is fixed in SP2010.  The http and you version number will be idenitcal if you install using slipstreamed images as the install will include the patches you have in you install.
Resolution:
  • You can't rely on the http header SharePoint version number returned via the page requests to determine the version of SharePoint you are looking at.
  • I recommend removing the http header info for SharePoint as it makes a hackers life marginally more difficult as they don't know what version you are patched to or originally installed.  They will also need to use another technique to determine if your website is a SharePoint server. 
  • Todd Bleaker has a simple technique for identify SharePoint public websites, "Since most people allow anonymous access to the images in the 60 Hive/12 Hive and there really isn't any reason to remove the default images (in fact it probably isn't supported), it is an easy litmus test to detect SharePoint.  However, I recently wanted to determine whether a site was SharePoint 2010 or not, but since visual upgrade is now a viable upgrade scenario and CPVW.GIF is not unique to the SharePoint 2010 I needed something new to look for. So, I poked around a bit and found that /_layouts/images/FGIMG.PNG isn't too hard to remember and it shows an equally unlikely image to be in a non-SharePoint 2010 site". 
More Info:
http://vspug.com/bobbyhabib/2008/05/16/getting-the-correct-moss-wss-version-for-each-server-in-the-farm/

http://www.sharepointdevwiki.com/display/SharePointAdministrationWiki/SharePoint+Versions

http://www.sharepointdevwiki.com/display/spadmin2010/SharePoint+2010+Versions

Update 28/03/2010 - Todd Carter has a post on versions of SharePoint Versions
Update 20/02/2012 - PS to determine SP edtition and patching level

Friday, 4 February 2011

MOSS export list SSL issue

Problem: I can't export a list to a excel spreadsheet file from a SharePoint 2007/WSS3.0 site is using SSL.  SP2010 exports https lists correctly. 
Initial Hypothesis: File is being exported however, when opening the *.iqy file, the error "Excel cannot connect to the SharePoint list." pops up. 
Resolution: This is a bug with 2 workarounds,
  • Option1: From excel connect to the list. or
  • Option 2: Save the *.iqy file, open it using notepad, chnage the url to use https instead of http (it occurs twice in the iqy file.

Issue in Document libraries in MOSS using Word 2010

Problem:  The business upgrades there Office desktop version to Office 2010.  If a user needs to add new documents into a document library running on MOSS.  Word 2010 opens and then throws the error "This file could not be found.".
Initial Hypothesis: Office(Word) 2007 and Office(Word) 2003 can create the new documents.  Office(Word) 2010 can edit a document added by a previous version or an uploaded document correctly.  The issue appears to be between Word 2010 and document libraries in MOSS when adding a new document under SSL.

I can open the full url to the word template correctly using IE and Word 2010, so the issue must be with the url that is crafted for Word 2010.

I was looking at the templates associate with each content type in my document library, the path is always relative however, as I am adding the the template it stores a relative value.

Resolution: The url that is requested using the new document derives from the content type's default document template.  My site uses SSL, and it looks like the path that SharePoint generate is incorrect (I need to confirm this using fiddler, but as I'm on my clients site using a locked down workstation and no access to the servers I can't see the url being generated).  Anyway, my fix is to save the full https path in the "Enter the URL of an existing document template".

Friday, 28 January 2011

Writing Windows Phone 7 Applications

Overview:  Windows Phone 7 (WP7) was released in the end of October 2010 on the HTC Mozart, Samsung Omnia 7 & LG Optimus 7 in the UK.  WP7 apps are written in .NET and based on Silverlight or XDA.  As a C# enterprise developer I always use Silverlight as this is for Rich Internet Applications (RIA).  Microsoft XDA is for games development.

Tooling:  Microsoft have great free tools such as expression blend and Visual Studio 2010 express for WP7.
There is a single download for all the tools including the Windows Phone 7 emulator.
VS has dedicate template for the WP7 in VS2010 that are a good starting point.
There is Intelisense and full debugging integration with the WP7 emulator.
Xaml is responsible for the UI and it's pretty straight forward especially if you have done ant Silverlight development previously.


Training: Microsoft have done a great job on providing getting started examples and video learning via Channel 9.  It really can't be simpler.  Take a look at Channel 9's Windows Phone 7 Development for Absolute Beginners.

More info:
Updated 25/02/2011 - SharePoint integration with Windows Phone 7 by B.K. Winstead 

Thursday, 27 January 2011

Information Architecture for SharePoint

Overview: I was speaking to a client recently about there SharePoint Intranet and I mentioned they should have a Information Architecture (IA).  This should preferably be done by an Information architect but at a minimum the organisation can get the IA from project stakeholders.  Below I list the 2 most commonly found IA representations approaches: Wireframes & Hierarchy/structure diagrams.

What is IA?
Wikipedia define IA as "Information architecture is the categorization of information into a coherent structure, preferably one that most people can understand quickly, if not inherently. It's usually hierarchical, but can have other structures".
For web based projects, the best 2 methods for defining IA are a hierarchy and a wireframe other useful tools are defining the taxonomy against the hierarchy IA diagram.  I have seen various techniques to achieve this but keeping it simple as listed below and having a separate annotated version defining the term set or formal business taxonomy at each level is useful.

Hierarchy IA Diagram
WireFrame
Read More:
http://www.informit.com/articles/article.aspx?p=1657659

Update 23 April 2011 - I have seen people looking for a starting point for an Intranet Menu structure, this is a generic option I propose for Intranets.  Please feel free to suggest your own structure.


Wednesday, 26 January 2011

Smartphone Development

Overview:  Over the past few days I have been looking at writing apps for the Windows 7 Phone & an iPhone app and I thought I would share my findings.

Development for all smartphones is done at the browser or application level.

Browser development is usually a subset of xHtml and there are issues such as on Safari using an iPhone does not supporting all the html elements and attributes of XHTML.

Application Development Run Down:
  • There are 5 big players in the smartphone OS market (palm is not 1 of them).
  • Microsoft have entered the smartphone industry with there OS "Windows 7 Phone".  Windows 7 phone is going to gain a large marketshare in the app store market.
  • Application development is big business and iPhone has had over 10 billion downloads already i.e. more downloads than people on the planet.  The app dev platforms I'm interested in are iPhone(iOS), Windows 7 Phone, Android and blackberry/RIM.
  • The smartphone market is shared between Symbian (Nokia and previously others), Android, Windows 7 Phone, Blackberry (RIM) and iPhone (iOS).
  • Symbian/Nokia sells the most smart phone units by a long way however, they don't have a nice sales and developement market for 3rd party application market like the iApp from Apple.  Additionally, users don't tend to use alot of apps or surf as much as say an iPhone or Blackberry.  Symbian may support Silverlight going forwards so from an RIA perspective this would make it pretty simple to develop and could help achieve better apps with more app writers. 
  • Android has multiple hardware manufactures that use the OS and it is owned by google, app development runs on Java and there are multiple programming languages for developing apps.  It has a open store, the OS is widely used and is a very good option for mobile developers to explore.
  • Blackberry/RIM use to be the enterprise smartphone of choice it is still a market leader but with stiff competition, it is still growing quickly in units sold (as the smartphone market grows at about 35% year on year) but it appears to be loosing market share.  This is definitely a platform you can't ignore as a mobile app platform.
  • iPhone, only Mac builds phones for iOS (not Cisco OS).  It has huge market share and the impressive consideration is the number of apps and surfing people that use iPhones accounts for.  iPad, iTouch also use iOS.  This post assumes iPhone is the only smart phone from Apple. iOS is an extremely important platform and is my 1st choice of platform to target.
  • Windows 7 Phone is going to get popular especially as there are alot of .NET and silverlight developers that can easily adapt to the Microsoft Windows 7 phone platform.  Tooling for developers is good and free.  The app store is easy to use so this has to a big player for the future.  In the short time MS have released Windows 7 phone, manufactures like Samsung and LG have sold alot of smartphone units with the Windows 7 Phone OS.
Original Source: Wikipedia 26 January 2010
Update: 11 Feb 2011 - Microsoft and Nokia have an agreement to win market share in the smartphone market.  This looks like good business for both parties.  Nokia is loosing ground and doesn't have a decent platform.  Microsoft have a great platform but no market share.  With Nokia's distribution and Microsoft playform/devlopers it looks like agreat match.   BBC news article.

Update 3 March 2011 - Apple has now sold 100 million iPhones as of Feb 2011.  15 million iPads where sold in 2010.