1/13/2010

SharePoint 2010: A Walkthrough of Converting 2007 Code to 2010

 

While I was experimenting with Forms Based Authentication for SharePoint 2010 I found that 2010 is still missing any user administration tools for FBA users.  For SharePoint 2007 there is a project on CodePlex (http://fba.codeplex.com/) that is a good starting point for site level admin tools. The only problem is that as-is it will not work for SharePoint 2010. 

This project turned out to be a good demo of what you may need to do to convert code from 2007 to 2010.

 

The key conversion steps:

  • Update the referenced DLL from the 12.0.0.0 version to the 14.0.0.0 version of Windows.SharePoint assembly.
  • Update the references in all of the ASPX pages from 12.0.0.0 to 14.0.0.0
  • Replace the master page used in the ASPX files with the 2010 applicationV4.master.
  • Set Visual Studio to compile the project using Framework 3.5  (2007 used 2.0, or 3.0 for workflow work) and compile the code. Make sure you target 64 Bit or “Any CPU”!
  • Edit the files used to create the WSP  (the CAB file)
  • Edit the files used to deploy (to the 14 directories instead of the 12 directories)

 

  1. First setup a SharePoint 2010 application for FBA. 

    One way: http://techtrainingnotes.blogspot.com/2010/01/sharepoint-2010-forms-based.html
    You will need to setup both the membership and the role providers to support the codeplex project.

    Also, edit the XML for the membership provider and set requiresQuestionAndAnswer="false" as the codeplex project does not support that feature.
  2. Go to http://fba.codeplex.com/, click the Source Code tab and on the right under “Latest Version” click Download  (confirm that you have found a ZIP file and not a WSP file)
  3. Extract the ZIP file. You should get a folder named FBABasic that contains the project
  4. Open the project in Visual Studio 2010 and let it do the project conversion (and let it remove the source “control bindings”)
    (You could use VS 2005, VS 2008 or even Notepad if you wanted to)
  5. Change the Target Framework from 2.0 to 3.5  - Click the Project menu and select Properties
    (Studio will have to close and reopen the project)
  6. In the Solution Explorer remove the Microsoft.SharePoint reference (this is for the 12 version)
  7. Add a reference to Microsoft.SharePoint 14.0.0.0  (was listed as Windows SharePoint Services in the 12 version)
  8. Do a Find and Replace through all of the ASPX files and change 12.0.0.0 to 14.0.0.0
    (I found 5 per page, 35 total.)
  9. Do another Find and Replace through all of the ASPX files and change “application.master” to “applicationV4.master” to add the 2010 look and feel to the page.
  10. Edit the Deploy.cmd, DevDeploy and UnDeploy.cmd files and make two changes:
    - Change the path from \12\ to \14\
    - Change the sample URLs (“http://wssdev”) to your FBA test application (Mine was http://maxsp2010beta2:85)
  11. The project has two post build events.
    Note: I personally don’t like to use Build Actions as you can’t see if they succeed or fail. Instead I manually run package.cmd and deploy.cmd in a command window so can see all of the messages.
    1. Package.cmd creates the CAB/WSP file and needs MAKECAB.exe to run. Find makecab.exe (C:\Windows\System32\makecab.exe) and either copy it to the project directory or edit Package.cmd and add the path for makecab.exe.
    2. Deploy you have already edited, but check it again.
  12. Make sure you are targeting “Any CPU” (or x64) and then build the application.
  13. If you are not using the post-build events then manually run package.cmd and deploy.cmd.
    Don’t be concerned if the first run of the deploy.cmd file displays a lot of errors as it is trying to retract a solution that has not been deployed yet
  14. Launch your FBA test site, login and then go to Site Actions, Site Settings and see if “Manage FBA Users” and “Manage FBA Roles” is there.

    Note that you will either get errors, or find no users, if you try to access these pages from the Windows Authenticated application.
  15. Test, test, test…

 

Things to do…

  • Add error handling
  • Add support for “requiresQuestionAndAnswer” and other Membership provider features
  • Add detection for when the pages are displayed in a Windows Authenticated application.

 

.

2 comments:

Anonymous said...

Nice article

Anonymous said...

I tried following your steps. Got it packaged and deployed fine. However when I try to activate it on a site I get an Access Denied error. When I look in the logs I find a lot of verbose stuff but one message stands out:
The SPPersistedObject, UpdateLayoutsSitemap Name=ULS_13866691-c6de-4546-a42f-fd90f737c1ad, could not be updated because the current user is not a Farm Administrator
I am logging on as a farm administrator to activate this!

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.