Showing posts with label SP2010. Show all posts
Showing posts with label SP2010. Show all posts

Monday 27 June 2011

Interested in Writing a Chapter for a SP2010 Community Book

About this book:  This book consists of standalone chapters written by various authors with real world experience of SharePoint 2010.  The content is predominantly non-technical allowing people involved and managing SharePoint 2010 projects to deploy SharePoint successfully within their business.

More info ...

Wednesday 1 September 2010

SP2010 AutoSPInstaller Prerequisite Install Issues (Codeplex PS project)

Problem: Install SP2010 using the CodePlex PowerShell Installer (AutoSPInstaller) without internet access.

Hypothesis: 
Add the following KB to the prerequisiteInstaller folder:
  • Windows6.0-KB968930-x64.msu (/POWERSHELL)
  • Windows6.0-KB976394-x64.msu (/KB976394)
  • Windows6.1-KB976462-v2-x64.msu (/KB976462)
  • Windows6.0-KB974405-x64.msu (/IDFXR2)
  • rsSharePoint.msi (/ReportingServices)
  • SpeechPlatformRuntime.msi (/Speech)
  • MSSpeech_SP_en-us_tele.msi (/SpeechLPK)
=====

Error: Error.  An unknown error occurred installing prerequisites at c:\....\AutoSPInstaller.sp1:388 char:14 ...

Fix: Reboot server and retry.

=====

Error: The tool was unable to install SQL 2008 R2 Reporting Services SharePoint 2010 add-in. Install process returned (0X643=1603).  Applies to the codeplex Powershell scripted install.
Fix: Only info I found suggested a re-run fixes the error. Simply re-running the prerequisite installer did not fix the issue for me. A similar error suggesting that i am using the incorrect version of rsSharepoint.msi relating to the Genva framework (claims) not Reporting Services.  I tried manually installing the Reporting services rsSharePoint.msi, it kept failing.  I also tried rsSharePoint_x64.msi, also failed.
Next I ran SharePoint install manually after the manual prerequisites was run as Administrator, failed.

Noticed I had 2 rsSharePoint.msi that are of a different size?  The file I used on 2 Sept 2010 on my Win 2008 R2 WFE was 36.9MB in size, my other was 39MB.  rsSharePoint.msi download

I use the version off the SQL media for getting Reporting Services wirking in the SharePoint mode.

=====

Error: rsSharePoint.msi wont install
Fix: There are version versions of rsSharePoint.msi, ensure you use the correct 36.9MB file.
I downloaded the correct version from http://go.microsoft.com/fwlink/?LinkId=192588
Incorrect 39MB Version as of 2 Sept 2010 .
These file have the same name but they are different and using Windows 2008 R2 for my install only the 36.9MB version works.

=====

Installation Notes for a 3 server NLB SharePoint 2010 farm

Monday 30 August 2010

Linq to SharePoint 2010 DSL extensions

I have been building a composite application for a client that has a heavy reliance on SPMetal.  There are several issues using SPMetal and I have spent time this weekend trying to figure out how SPMetal works so I could work around our issues.  I found this project from MS LINQ to SharePoint DSL extensions.  Pretty impressive tool.

A few years back I went to Microsoft to hear about Domain Specific Languages (DSL), at the time I thought it was pretty amazing but couldn't see any benefit for me and thought it was going to be pretty niche in fields like academic research.  I was wrong and this project is definitely worth a look it you are going to use SPMetal, you may not need or want the extra ability but pretty useful.  Olivier Carpentier has written a good user guide & made a pod cast to go along with the unsupported MS project.

Friday 20 August 2010

SPMetal is throwing a ThreadAbortException

Problem: I am inserting new items into a list using Linq-to-sharepoint (SPMetal), my code throws a ThreadAbortException exception. 

Initial Hypothesis: When I run the code as a Site Collection Owner the new list item is inserted.  So this is a permissions issues.  I increase the permissions on the user that can't insert the list item.  It works so this is clearly a permissions issue.  After the user tries to perform the insert list item, they are directed to the "Error: Access Denied" message on the web page.  Clearly the error message is misleading however, SharePoint seems to understand the ThreadAbortException is a permissions issue.  The issue is the user does not have sufficient permissions to perform the action.  By elevating the user permissions the error goes away.  All well except the error logging is throwing an odd error, after some digging this issue has been blogged before however not for LINQ to SharePoint.

Resolution: Assign the correct permissions to the user performing an action.

Monday 26 July 2010

Problems with SPMetal in SharePoint 2010

Overview: I have been doing a fair amount of LINQ to SharePoint lately and I have found a couple of issues, my vitriolic rants are:
  1. SP metal can run against external content type (BCS) - external content types don't get created by SPMetal;
  2. Hidden fields are not available to the SPMetal created proxy i.e. createdby, modified. Parameters.xml can be changed to display these hidden fields;
  3. Only SharePoint Foundation field types are generated.  Column types are not picked up by SPMetal include the "Managed Metadata columns", "Publishing Html" or "Publishing Image". Additionally any custom created columns are not included by SPMetal;
  4. Anonymous LINQ needs a work around.  Update 27/11/2010, August Cumulative Update (CU) for SharePoint 2010 apparently fixes the anaonymous LINQ to SharePoint issue. Ensure you get the latest CU due to the re-release issues.
  5. Update: 08 Oct 2010 - List attachments are not picked up by SPMetal.  You will need to use the Server side object model or extend SPMetal using a partial class.
  6. Update: 14 Oct 2010 - Multiselect columns are not update-able with multiple values using LINQ to SharePoint.  You can update with 1 value only.
  7. Update 18 Oct 2010 - SPMetal does not like spaces in the url to the site that it generates off. Error the web at 'http://demo.dev/sites/my site' could not be found.
  8. Update 27 Nov 2010 - Using Linq to SharePoint across site collections.  Scope is to the current site collection.

LINQ to SharePoint Posts on this blog
Extending SPMetal for field columns no available to SPMetal by AC (Update) or AC
CAML query for retrieving Publishing HTML and Publishing image columns
Configuring SPMetal default generated code

To see the CAML generated by SPMetal:
StringBuilder sb = new StringBuilder();

System.IO.TextWriter tw = new System.IO.StringWriter(sb);
updatedataContext.Log = tw;
// CAML Query here i.e. var x from customers select customers;
string camlOut = sb.ToString();  // CAML generated.

Update: 09/10/2010 Extend SPMetal to retrieve list attachments

Friday 23 July 2010

SharePoint 2010 Ribbon for Developers

Overview: SP2010 implements the ribbon UI. Ribbon in the same as word 2007 ribbons in that it provides contextual actions that the user can use. This post looks at styling and controlling/extending the ribbons functionality.
Notes:
  • Ribbon is styled using corev4.css, this changes depending on if you apply a theme. css styling starts with "ms-cui" in the css.
  • SPD can add custom actions.
  • Ribbon is controlled by SP file 14\Template\global\xml\CMDUI.xml, this is merged with our custom xml file at run-time to result in an extended ribbon displayed to users.
  • Deploy the custom ribbon xml using a feature.
  • Buttons can be easily added or existing buttons replaced or hidden using XML declaratively to include custom ribbon actions.
  • Ribbon can also be modified programmatically (SPUserCustomAction)

Thursday 22 July 2010

Deploying to GAC vs bin folder in SP 2010

Problem: Do we deploy our to the GAC or the bin directory.

Answer: It depends on what the dll is, who needs to use it and is the SharePoint farm dedicated. You need to understand Code Access Security (CAS). Key point is dlls in the GAC (Global Assembly Cache) have full privileges. dll's in the bin have restricted privileges. You can change the level of permissions for dll's in the bin using CAS policies. SharePoint has 2 policys you can use by default: WSS_Minimal or WSS_Medium (same options as in MOSS). You can also use ASP.NET's policies, there are about 5 of these policies in .NET and the highest level is the "Full Trust" CAS policy. You can also create your own policy. Change the CAS relating to you dll's in the bin via your applications web.config.

Only code that runs in the IIS workprocess can be placed in the bin.  Deploying to the bin minimises permissios but certain tasks such as timer jobs, workflows, service applications and event receivers only work in the GAC.  Deploying to the GAC allows for multiple versions of the dll to exist in the GAC provided versioning is used.  Bin deployment can't have multiple versions.

Note on Sandboxed solutions - runs is the "Microsoft SharePoint Sandboxed Code Service", sandboxed solutions have restricted rights to what it can do. It can permorm basic SP Server side OM's unde the SPSite (Site collection) object under the current SPSite which makes sense. Sandboxed code is deployed to the solutions gallery under the current SPSite. You can also use sandboxed solutions with code proxyies to achieve higher rights operations.  So as you can see sandboxed solutions do not go into the GAC or the bin and CAS is not an issue.  Real option is between GAC + using a Sandbox solution.

Sandbox solutions are good in restricted high usage environments as they allow SharePoint Administrators to validate (manually and via solution validators) the code being uploaded.  Developers are limited in what they can do to the environment.  The counter stop inefficient code once the threshold has been passed.  Administrators can monitor sandboxed solutions to easily identify poorly performing code.

My general rule is: Deploy my custom code to the GAC except if it's not trusted i.e. 3rd party code or there is a business reason/policy not to. It makes dev easier but is not ideal in that best practice decitates that you should apply the minimal levels of security permissions to your code.
Additional Info: Microsoft SharePoint Team Blog on application development.
Great blog on sandboxed solutions

Thursday 15 July 2010

Deploying resources using features

Overview: Feature deployment has changed in SP2010 from MOSS. In MOSS we added files to the 12 hive and deployed them via a feature. In SP2010 the feature is package slightly differently and is marginally easier to create using VS2010 because of the tools. I have VS2010 and the CKSDev tools installed.

Steps to add an xslt file to your style library using a feature in SP2010:
1.> In VS2010 create a new Element;
2.> Under the element add and xslt, change the "Deployment Type" property;
3.> Move the elements to "Items in the Feature" default is "Items in the Solution";
4.> Modify the elements.xml file;

5.> Ensure the itemStyleCustom.xsl exists in the Xsl Style library.

Wednesday 14 July 2010

SP2010 CQWP customisation

Overview: Content Query Web Part (CQWP) in SP2010 is similar to in MOSS. This post walks thru using the CQWP to display a custom list and custom columns while outputting custom html via a custom xslt.
CQWP (need the publishing feature enabled, this creates the styles library and add the CQWP) by default uses the xslt /Style Library/XSL Style Sheets/ItemStyle.xsl.

Steps:
  1. Don't write over ItemStyle.xsl as this si supplied by SP2010 OOTB. Rather create a new xslt and put it into the styles library. Build up the xslt, I based my file on the itemstyle.xsl file, see rules for getting the output you are looking for using How to: Customize XSL for the Content By Query Web Part
  2. Custom xslt formatting, I always add the following code in case I want to see what the available fields are:
  3. Deploy the custom style sheet via a feature.
  4. Create a new Custom list called "Pets" and add columns for Title, Age & Status (choice):
  5. Edit your custom xslt to display for "Pets" as shown below:
  6. Add a new CQWP to your page. Configure it to display items from your new list (Pets).
  7. Change the "Presentation" section, "Item Style" to Show "Pets". Apply the Changes:
  8. CQWP displays as:
  9. Edit the CQWP "Age" property to "Age"
  10. Edit the CQWP "Age" property to "Status"

    Monday 12 July 2010

    Sharepoint 2010 Dialogs Framework

    Problem: Use the dialog framework to edit information on a SharePoint composite page.
    Hypothesis: Dialog framework can open existing pages and pass back values to the calling page. The pass back value can be more than just a simple parameter such as a string. You can return fairly complex flat objects. The example below, displays multiple addresses, allows the user to edit any of them via a modal dialog. and returns the updated address along with the id of the element address to change. To use the dialog framework modals you need SP context so use any of the client OM's or the server OM (i.e. you can't use html unless to load the SP context)
    In the parent page inside javascript add the following 2 functions
    function OpenDialogAdr(myurl) {
    var options = SP.UI.$create_DialogOptions();
    options.url = myurl;
    options.width = 200;
    options.height = 100;
    options.dialogReturnValueCallback = CloseCallback;
    var dialogSP = SP.UI.ModalDialog.showModalDialog(options);
    }
    var messageId;
    function CloseCallback(dialogResult, returnValue) {
    if (dialogResult === SP.UI.DialogResult.OK) {
    var adr = returnValue.adr;
    var id = returnValue.id
    $("#adr-sales-" + id).html(adr);
    }
    }


    Add a link with the appropriate js:
    Add the child page, that will return the new address and the id of the item to change.

    function onUpdate() {
    var adrs = document.getElementById('txtAdr').value;
    var ids = document.getElementById('txtId').value;
    var mydata = {
    adr: adrs,
    id: ids
    };
    SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, mydata);
    }
    function onCancel() {
    SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult
    }

    Resolution:
    The dialog framework is good for displaying additional information. It is similar in nature to using jQuery & the lightbox plug in.

    Resources:
    Working with SP2010 modal dialogs

    Tuesday 29 June 2010

    Logging custom error for SharePoint 2010 custom code

    Problem: SP2010 has good logging in the ULS logs. Unlike MOSS you can write to the ULS logs in SharePoint 2010, allowing for a single consistant place to log your errors. The event viewer logs errors to a lesser extent than ULS where administrators tend to look first. However, on all projects the topic of how and where to log custom coding errors comes up. What level should the event be caught at and where should they be placed. I have seen multiple was of doing this and it really comes down to what the previous projects used and how do you want to monitor errors.
    Tips:
    1. Don't write code to function using error catching i.e. I have seen developers catch a specific error and from this position they know the code is to follow specific logic -it's very inefficient. Write code to deal with all situations.
    2. Catch errors as specifically as possible, then decide if the error should be bubbled up or can it be dealt with via the logs. But catch the appropriate errors so they are logged.
    3. You can write to Unified Logging Service(ULS) logs but these are often not checked or hard to find issues you have thrown up in your code, so consider using a logging block such as Microsoft's Enterprise Logging blocks or Log4net. Ted Pattison suggests writing to ULS and he know his stuff so if you don't have another specified logging policy write to the ULS. And if you do have another logging method consider writing to the ULS anyway.
    4. There are a lot of logging applications for .NET, and most companies tend to have logging code ready for implementation on your SP 2010 project.
    5. I have seen a MS gold partner use tracing on all projects. So when an error occurs they turn on tracing and try replicate the issue in production environments. Far better to catch errors so you can get your issues resolved quickly and don't need to change config setting or leave tracing enabled on the live production boxes.
    6. A web part error can cause an entire page to throw an application error. However don't throw try catch blocks around all code, rather try catch the errors at more appropriate junctions such as at the service layer. Once again it really depends on the WP.
    Summary: Avoid using errors for logic (pretty obvious). Log the errors to a distinct area (database, file system(xml files are pretty useful)) to identifying where and what the issue is. Catch specific errors -try not to catch general exceptions and if you do need to catch general exceptions make sure you have looked for more specific exceptions such nullrefobjectexceptions.

    More Info:
    MSDN SharePoint Logger - http://msdn.microsoft.com/en-us/library/ff798361.aspx
    Writing to the ULS
    Update: 5 Dec 2010 - Writing to ULS using SP2010 by Waldek Mastykarz
    Update: 18 Jab 2011 - MSDN article on logging and debugging

    The SharePoint Logger
    using Microsoft.Practices.ServiceLocation;ILogger logger = SharePointServiceLocator.GetCurrent().GetInstance();
    using Microsoft.Practices.SharePoint.Common.ServiceLocation;
    using Microsoft.Practices.SharePoint.Common.Logging;
    IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
    ILogger logger = serviceLocator.GetInstance();
    logger.TraceToDeveloper("Unexpected condition");

    Update 14 Dec 2010 - ULS Viewer - Tool to view ULS log and filter data
    Update 23 Dec 2010 - Tracing using CorrelationId