Sunday, 10 February 2013

Alternate Access Mappings and SPFieldURLValue fields

Be careful if you're trying to programmatically pull back the value of a Hyperlink field when your site is using Alternate Access Mappings (AAM).
If the value of the Hyperlink field is pointing to an object within the current SharePoint site, the SharePoint front end will automatically update the URL for the AAM site you are currently using.  BUT if you are pulling the value programmatically it will always default to the URL of the default AAM site.


UPDATE:
Better Way to Fix:
I discovered an even better to fix this problem and it all has to do with how you open your SPSite Object.
For example if you do
SPSite site = new SPSite(SPContenxt.Current.Site.ID)
It will open the site in the default zone, which will then always return the URL of the default zone.
But if you do the following:
SPSite site = new SPSite(SPContext.Current.Site.ID, SPContext.Current.Site.Zone)
It will open the site in the zone the user is currently in and return the correct URL.

To fix this, you must turn the URL into a relative URL and then it will go to the AAM of the site you are currently logged into.  One way to achieve this is as follows:

SPFieldUrlValue linkfield = new SPFieldUrlValue(listItem["URL"].ToString());

string returnValue = linkfield.Url;

            try
            {
                using (SPSite site = new SPSite(returnValue))
                {
                    return returnValue.Replace(site.Url, string.Empty);
                }
            }
            catch
            {
                //swallow exception from Site Not Found
                return returnValue;
            }

How to Properly use RunWithElevatedPrivileges

RunWithElevatgedPrivileges will run the code block with Full Control rights even if the current user does not have full control.  This piece can be very useful, but must be used carefully to avoid creating a security hole.
The interesting part of this method is that for any objects to be run with this elevated context, they must be created within the RunWithElevatedPrivileges block.  This may seem obvious but lets take a look at a couple examples:
  
SPWeb web = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()  
       {  
         PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
         ...
       })  

This method will result in an unauthorized error, unless the logged in user has enough permissions to open a Publishing Web object.  But we said the object must be created within the Elevelvated Permission block, so it looks like an easy fix to the above code:


SPSecurity.RunWithElevatedPrivileges(delegate()  
       {
        SPWeb web = SPContext.Current.Web;
         PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
         ...
       })

This method will also result in an unauthorized error.  Wait you say, the SPWeb object is created within the Elevated block, so it should work.  The issue is that the SPContext.Current.Web method returns an SPWeb object under the context of the current user, not the Elevated user, regardless of where the method is run...so how do you get an SPWeb object to run under the elevated permission?  You need to open the web using the GUID constructor, like this:


Guid siteID = SPContext.Current.Site.ID;
Guid currentWebID = SPContext.Current.Web.ID;

SPSecurity.RunWithElevatedPrivileges(delegate()
            {
             using (SPSite site = new SPSite(siteID))
                {
                    SPWeb currentWeb = site.OpenWeb(currentWebID);
                    PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
                    ...
                }
            })


The difference being the first and second examples are returning an already created SPWeb object, that was created under the current users context.  The last example is returning newly created SPSite and SPWeb objects, since they are within the elevated code block they will be created under the elevated context.  Now everything should work as expected, regardless of who is logged into the site.

             



Wednesday, 6 February 2013

Problems opening office documents in SharePoint 365


I was trying to open a SpreadSheet from a SharePoint 365 site only to keep getting this error message:
The document could not be opened for editing.  A Microsoft Foundation compatible application could not be found to edit the program.

Which is really odd since I do have excel installed on my machine.  I found lots of blog posts suggesting to verify that certain SharePoint add ons are enabled in IE to ensure you are using the 32 bit version of IE, ensure office is installed, but nothing really useful as all I could check yes to all their suggestions: (http://community.office365.com/en-us/forums/175/t/59242.aspx).

Turns out that the activeX control that is used by SharePoint 365, and probably SharePoint on prem although I don’t know for sure, comes with the Office install.  So the suggestions were on the right track, you need to have office installed…but here is the kicker.  It all depends on which version of office you installed 32 bit or 64 bit.  If you have installed the 64 bit version of office, you need to run the 64 bit version of IE for this activeX control to work properly and vise versa.

Now you know.

Tuesday, 17 July 2012

SharePoint 2013: Initial Thoughts


Some initial thoughts after skimming through all the material Microsoft posted here: http://www.microsoft.com/en-us/download/details.aspx?id=30361
Over all this release looks to be more about improvements and refinements.  It does not contain any major overhauls like the Service Application layer of SharePoint 2010.  That being said there are some exciting new features.

Note:
SharePoint 2010 == SharePoint 14 == 14 Mode
SharePoint 2013 == SharePoint 15 == 15 Mode

Architecture:
This version of SharePoint is built on .Net 4.0.  I suspect it is using the new .NET Web API for their REST web services.
Looks like it would be possible to have a Service Farm in the cloud being consumed by an on-prem SharePoint farm.  In SharePoint 15 they have removed the database permission required in cross farm sharing of service applications.
Single Web Application can now consume both local and remote services.

Service Applications:
The service application architecture is the largely the same as SharePoint 2010.
Web Analytics has been rolled into Search.
Office Web Applications is no longer a Service Application.  Instead it now requires its own set of VM(s).
New: App Management Service – To support SharePoint Apps from either the Market Place or Corporate Catalog
New: Translation Service:  Cloud based translation service for documents, pages and sites.
User Profile Application now includes the User Profile Replication Engine.  In 2010 this was a separate download required to replicate User Profiles and social to another farm.  This was very handy for Disaster Recovery.

Request Management:
SharePoint 15 provides the ability to route requests based on the following information:
·         Url
·         UrlReferrer
·         UserAgent
·         Host
·         IP
·         HttpMethod
·         SoapAction
·         CustomHeader

This could prove to be one of the most useful features of the new version.  This allows you to reject potentially malicious requests.  It could also allow you to route request to certain servers based on the data requested or the person who sent the request.  In a large organization this could allow you specify sets of servers to handle requests for certain departments.

Custom Code:
SharePoint 2013 will still handle Farm Solutions (same as 2007 & 2010) and Sandboxed solutions.  In addition it has added SP Apps.  This, apparently, will be the preferred method of deploying solutions to SharePoint 15.
SP Apps:  Not really sure how solutions are going to map to an app yet, but here some details on how an app will function:
·         One App == One Web == One URL
·         Only deploy Web Scoped Features (SPWeb)
·         App features are not available outside of the App
·         End users cannot manipulate the app web with SharePoint Designer or the browser
·         App Package will contain: Pages, Scripts, Styles and Manifest
·         App can be hosted on: A Developer Server, Azure, Any SharePoint server
·         A SharePoint farm can use Apps from the Market Place or from their private Corporate Catalog
·         Separate license for each app (The App Management Service will manage all these licenses)
·         Looks like web config must have Trust Level set to Full for apps to work
·         Can be built in the new version of Visual Studio

Upgrade:
Looks like there have been some more improvements to the upgrade process from SharePoint 2010.  Most notably is there will be a SharePoint 2010 mode, like Visual Upgrade but more.  SharePoint 15 will have all the SharePoint 14 features, when in SharePoint 2010 mode the site (and all customizations) will still be running all the SharePoint 2010 code and features and all customizations will still live in the 14 hive, not the new 15 hive.
Preferred method for upgrade is the database attach method (same as 2010).  The following databases will support this method:
·         Content Databases
·         Project Database
·         Search Admin
·         Profile
·         Social
·         Managed Metadata
·         Secure Store

PowerShell Commands: Test-SPContentDatabase (same as 2010) and the new Repair-SPCotnentDatabase to fix the issue discovered in the Test-SPContentDatabase command.

A Site Collection Health check that will run before the upgrade to ensure everything is ok before upgrade.

Ability to create side by side copies, one in 14 mode and one in 15 mode that can be run at the same time.

You can also create new site collections in 14 mode.  This could come in handy during a migration.

Social:  Haven’t read too much about this, but the images look very similar to the NewsGator sites we’ve setup…

That’s it for now

Tuesday, 10 July 2012

SharePoint 2010 Install Error


During a recent install of SharePoint 2010 I got this error message:
An exception of type System.Security.Cryptography.CryptographicException was thrown…

There was a little more to it, but not really anything of help. 

I googled the error message and found many blogs that suggested giving Network Service full control over the 14 hive (SharePoint root).  This not only seemed like over kill but also a security hole, there is a good reason why the Network Service account does not have full control over the 14 hive.  

Not liking the popular fix, I dove in a little more and found a much easier and secure solution.

When you run the SharePoint 2010 Products and Technology wizard, be sure to right click and select “Run As Administrator”

…that’s it. 

Monday, 4 June 2012

Productively Wasting Time


Let’s all admit that the majority of stuff within Twitter is a waste of time.  Let’s also admit that there is no real compelling business case for adding a micro blog (Twitter style feed) to your corporate intranet.  Now that we're all on the same page, does that mean we just throw out the idea of the Social Enterprise or Enterprise 2.0? 

Of course not.  But this also doesn't mean that we throw the concept of ROI out the window either.  We all know that employees are going to waste some time throughout the day regardless of what you provide them with.  For some it's the coffee run, or the water cooler; for others it’s the first 10-15 minutes of a meeting they spend catching up on what's new and how's the family doing before getting down to work.  The point is they are already "wasting" time.  Or are they? 

As an enterprise you'll need to accept that the vast majority of posts on your corporate micro blog will not have any enterprise value.  But that is not to say they are worthless, they will have community value.  They will build connections between employees.  They help build a sense of community within your organization.  It will enable your employees to productively waste their time.

This sense of community will encourage people to share their lessons so the community does not have to repeat the same mistakes.  These lessons will not always be ground breaking but if they save some members of the community just 10 minutes, it adds up fast.  More importantly it spreads this tacit knowledge throughout the organization, where it can be built upon.  As they say a rising tide lifts all boats.

This sense of community can also encourage mentorship.  Your organization may already have a mentorship program in place, but generally this is only for a select few or people in the organization being groomed for high level management or C Level roles.  This makes sense as it takes time to be a mentor.  But what if one person can be a mentor to many?  That is another benefit of the social enterprise; it allows more people to take advantage of the stars within your organization.  It also removes the formality so the whole mentorship piece becomes more informal and more elastic taking advantage of the different strengths within your organization.

It also provides a way to recognize rising stars.  The old adage that it's not about what you know, but who you know goes out the window to a degree by allowing employees to raise their own flag.  The social enterprise empowers employees to show off their skills and knowledge.  It also provides a mechanism for their contributions to be recognized regardless of how well they play the politics game.

I think we all agree, regardless of where you are in the corporate tree, that a sense of community within an organization is very important.  It's difficult to put an ROI on taking your employees out for some drinks or a meal to celebrate an event.  But we have all accepted that although we may not be able to measure the value of a happy employee we know it's important and most people are happier when they have that sense of community.  The Social enterprise is simply building off what we already know about the importance of community.  By moving part of the community interaction online it enables employees to build connections with parts of their organization they may not have been exposed to before.  It also enables the organization to record that community knowledge and present it to a larger audience where it can be further built upon.  Where that path leads will be unpredictable.  What we do know is that when people share ideas, good things happen.  Maybe the question needs to be looked at from a different angle. Can you afford to not have your employees productively wasting their time?  Maybe there is business value in the Social Enterprise after all.

Saturday, 2 June 2012

Why would I share?


Enterprise 2.0 is  all about knowledge sharing.   The advantage of knowledge sharing for the enterprise is obvious, but what about the individuals?  What is in it for them?  Why would I share?

We are all taught from a young age the importance of sharing.   As we grow we are also taught there needs to be a balance.  After all you do not want to be taken advantage of.  Only share with people that are your friends, people that are nice to you, but don't give away everything.   In school it can be seen in the lunch room.  Sure it's nice to share a few chips from your lunch,  but you also need to make sure you don't go hungry.  As we get older, it moves to money.  Most of us are willing to share money with family, less money as the friendships grow less intimate,  but what happens when a stranger asks you to spare some change?

For many of us knowledge, in general, is a large part of our identify.  Our knowledge is what makes us unique, separates us from the pack.  In the enterprise our knowledge is our currency.  Knowledge gives an individual a competitive advantage over their peers.  There is a cost, in time and effort, to the individual in acquiring knowledge.  Their return on investment is the competitive advantage and recognition that the knowledge could bring.  Why give that up for free?  How do we still give people the return on the investment made on gaining knowledge while still encouraging them to share?

As you can see, which I'm sure is not a big surprise to anyone, there are some significant hurdles to overcome with user adoption.  The value in Enterprise 2.0 is only visible when users actually use the system.  In other words if no one is sharing there is no system.  So to drive adoption and see value from your investment in enterprise 2.0, you need to be able to answer the question: Why would I share?

If you’re a glass half full kind of person you will look at the above piece and point out that all I've shown is that people do indeed want to share.  They just need the correct environment to do it in.  How do we provide that?

It looks like your site must achieve two main goals:
  1. Provide a Return on Investment to the individual for their knowledge
  2. Establish and foster communities that provide the close relationships that truly drive sharing

If you step back and take a look at some of the more successful web 2.0 sites you'll notice these two items are very prominent.  One example is a site  like Stack Overflow that allows people to ask and answer questions on a variety of technical topics.  The site is leveraging existing communities that are already out there for these technologies, although does provide a platform for these isolated geographical communities to merge into a larger online one.  The site also provides users an ROI on their knowledge  by providing user recognition (badges).   It allows users to vote on answers provided by different people.  The more votes you get the more points you get, the more points the higher your ranking, the higher your ranking the more people will recognize you as a subject matter expert.  A different type of example is a site like LinkedIn.  LinkedIn allows you to build your own community by connecting to people that you know.  It also provides groups to allow people to ask and answer questions.  The difference here is on the ROI the system provides for knowledge sharing.  The ROI here is the ability to show your knowledge to potential employers as well as industry peers, to show yourself as a subject matter expert and give yourself a competitive advantage while also helping your community.

Why would I share?  Seems the answer is simple: To either help my community or to help myself, ideally both.  Does your Enterprise 2.0 site provide that?