Wednesday, May 11, 2011

Play video and media files in SharePoint 2010 sites part I – Option comparison

There are several different ways you can play or video media file from a SharePoint 2010 site. In summary, we have explored three different ways on SharePoint 2010. Here is the list of three different ways we have explored on SharePoint 2010.
  1. Use out of box web part to play audio or video media file
  2. Use SharePoint 2010 to play audio or video media files on Media server
  3. Use third-party media player to play audio or video media file
There are pros and cons for each different one that I would like to share with you. Based on your business requirement, you may select different implementation. Let's start with out of box web parts.

1. Use out of box web part to play audio or video media file
There are three different ways you could use out of box web part to play media file.You could check this excellent blog how to setup each of them in details.
  • You can add a Media Web Part to the page to play an individual audio or video file.
  • You can configure dynamic displays of video or audio by configuring the Content Query Web Part to display audio or video files
  • Or you can embed a video from a third-party video sharing site by using embed code.

The first and easiest way is to use the Media Web Part to play media file. The pros is it's easy to setup and you could follow up this excellent blog on the procedure. However,  the cons is if you use embed code or sharing links for pages that host video, they will not work. For example, you could not play youtube video using youtube URL like http://www.youtube.com/v/09-M-S7Og0o&hl=en_US&fs=1& in the configuration. This approach only display the static media file and could not display dynamic file. There are limited formats this web part will support

The second option to use Content Editor Web Part to play media file. The pros for this is you could display one file or multiple files dynamically from the filter. The cons is that you need to know little xml file format. Here is example to setup to play youtube.
  • Use Content Editor Web partEdit page and add web part
  • Select “Content Editor Web Part” under “Media and Content” and add to the page
  • Click the empty space of the web part and it will display the ribbons
  • Under Editing Tools, click HTML and then Edit HTML Source and type in the following code
               <div align="center">
                       <embed src=" http://www.youtube.com/v/7ByiLIosTPA&hl=en_US&fs=1&"
                                autoplay="false"
                                loop="false"
                                width="600"
                                height="400"
                       </embed>
              </div>


You could also add JQuery to display list of the files for this web part. Please see other blogs for details.

The third option to use embed code from a third-party video-sharing website to add a video to a page, you can do so by adding the embed code to the Content Editor Web Part. The pros of this approach is very flexible and the cons is you need Designer permissions to do this and may be very tedious for non programmers. The code is similar like this.


             <object width="480" height="385">
                    <param name="movie" value="http://www.youtube.com/v/EODwh5hS7ZY&hl=en_GB&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6"></param>
                   <param name="allowFullScreen" value="true"></param>
                   <param name="allowscriptaccess" value="always"></param>
                   <embed src="http://www.youtube.com/v/EODwh5hS7ZY&hl=en_GB&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>
               </object>

2. Use SharePoint 2010 to play audio or video media files on Media server
Microsoft provides Streaming Media Services that enables you to manage delivery of live or on-demand digital media content, including Windows Media Audio (WMA) and Windows Media Video (WMV), over networks by using administrative interfaces in Microsoft Windows Media Services 2008. If you need to check the details on the installation, you could check the SharePoint Gorge blog.

The pros of this approach is you have the separate Media Server to handle all the different format of the media and the size of the file. As a result, it could support all different media formats and large files. The cons is the installation is complicated especially on the Video Transcoding installation and configuration. In our case, we have setup the architecture to allow SharePoint users to download files to SharePoint and we handle the media file transcode and decode from the back end. Here is the summary of the architecture for your reference.

Here are the procedure we handle the media files so end users will not even know media files are steaming from media server.
  • A user uploads a video to the Video Library
  • The event receiver copies the video and a configuration file to a share on the WMS server
  • Windows service on the WMS server sees the new configuration file, reads the configuration information and uses that to transcode the video if necessary (WMV files do not need to be transcoded)
  • After transcoding the video, the Windows service will place the final video into the folder mapped to the WMS Publishing Point (making it available for on-demand streaming)
As I mentioned before, the major problem is the codec installation on the Media Server in order to support multiple formats. The sequence of the codec installation is also critical to make sure all formats could be played. Here is the partial codex we installed with proper sequence.
  •      Install Cook codec            
  •      Install FLV Splitter
  •      Install RRM Splitter
  •      Install Real Alternative
  •      Install MpegDecoder012
Some of the codec are free to download but several are not. If you need to support some formats, you need to purchase the codec.

3. Use third-party media player to play
After we explore the out of box web parts and Microsoft Media Server, we found neither of them could satisfy our end users requirement that is users should be able to setup the page and play different media formats themselves without IT involvement. Out of box web parts could not support all media formats or need some coding skills. Microsoft Media Server needs IT involvement to setup the back end and configure the connections to Mediaa server. If you want to have a simple way to allow end users to utilize SharePoint 2010 to play media and video, the following third party Media Player Rotator Web Part probably is one of the best options for you now.

We looked at this Media Player Rotator Web Part. End users could either selects a random media file, a specific media file or a media playlist from the specified Sharepoint Picture or Document Library. The Microsoft Media Player plug-in is used to play back the media files.

Supported file formats are MP3, SWF (Flash), FLV/F4V (Flash Video), PDF, AVI, WMV, MP4, MPG, MPEG, YouTube, ASX, RTMP (Streaming Media), MOV and M4V (QuickTime). You could display
a single static movie or list of files. You could display YouTube videos or any files from Sharepoint List or Library.

There are two drawbacks on this web parts. It does not support Target Audience as out of Media Web part does. It does not support streaming and as a result, web part requires media players (FLV, Windows media and Quick time) should be installed on client or server systems, otherwise it won’t play any video file.

With more demanding on the Media and video file support from SharePoint users, I'm hoping Microsoft could come up much easier way to support all different formats in the near future. May be SharePoint 2015?

Tuesday, May 10, 2011

How to fix SharePoint 2010 excel service error "System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances"?

If you enable to display excel file in browser on SahrePoint 2010, you could setup using the following steps.

Go to list library such as Shared Document -> Library -> Library Settings->Advanced settings->Opening Documents in the Browser -> select "Open in the browser".

However, we run into error listed bellow:

ExcelService.PostProcessRequest: Excel Server Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Office.Excel.Server.CalculationServer.ExcelServerApp' threw an exception. ---> System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)     at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock)     at Microsoft.Office.Server.Diagnostics.ULS.SendWatsonOnExceptionTag(UInt32 tagID, ULSCatBase categoryID, String output, Boolean fRethrowException, TryBlock tryBlock, CatchBlock catchBlock, FinallyBlock finallyBlock) .....

In order to resolve this issue, you could try the following procedures.

  1. Verify Excel Services Application is running correctly from central admin
  2. Verify Excel Calculation Services is in Started status
  3.  Restart the Excel Calculation Services
If Excel Calculation Services restart could resolve it, the worst case is you need to restart SharePoint 2010 servers and this issue should be resolve. I'm not sure the root cause of the issues right now. If you have better idea on this, please share with me.

Thursday, May 5, 2011

The security validation for this page is invalid error when enable SharePoint 2010 Site Recycle Bin features

After we install the Microsoft IT SharePoint 2010 Site Recycle Bin previous named Site Delete Capture tool has been released from CodePlex. We had issue when creating our sites using customized site definition with Site Recycle Bin features activation. We noticed the below error in the log file, which saying the error while activating Site Recycle feature but the real issue is with customized feature after site created.

“Failed to activate feature 'SiteRecycleBinSiteFeature' (Id 78b94e15-23ce-43f9-8036-babd847497d1) associated with site template 'QUALCOMMDEPT#1' at scope \"http://sbx01:80/sites/Harry1/ww/pp\".  Exception: Microsoft.SharePoint.SPException: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again”


The customized feature after site creation will setup groups w/ unique permissions, enabled auditing on Document library, add portal connection URL, add some content types, disable designer setting, and setup search setting.  The feature code looks like as following:

                           web.AllowUnsafeUpdates = true;
                            if (web.IsRootWeb)
                            {
                                SPSite SiteCol = web.Site;
                                CreateGroupPermisions(web);
                                CreateAuditSettings(SiteCol);
                                CreatePortalSettings(SiteCol);
                                AddContentTypetoDocsLibs(web, "Shared Documents", "Link to a Document");                               
                                CreateDesignerSettings(web.Site, false, false, false, false);
                                CreateSearchSettings(web.Site);
                            }
                            web.Update();
                            web.AllowUnsafeUpdates = false;


We found other developers have reported similar issues and here is the solution they recommend to resolve it.

Add the following two lines besides AllowUnsafeUpdates = true.


               //Disabling the from digest :-
              SPWebapplication.FormDigestSettings.Enabled = false;

              //Your original code listed above here
              //Enabling the from digest :-
              SPWebapplication.FormDigestSettings.Enabled = true;


This way you should resolve the "The security validation for this page is invalid." SPException.

Wednesday, May 4, 2011

April 2011 CU for MOSS, SharePoint 2010, and Project Server 2010 published

The April 2011 Cumulative Updates has been release for SharePoint Foundation 2010,  SharePoint 2010 and Project Server 2010. They are available for download at:
Microsoft still hasn’t publish corresponding KB articles with descriptions of the CUs on the official site, so there may be more details soon. Please be careful on any CU and we had bad experience on all previous CU.If you upgrade project server, you also need to upgrade client components.

I’ve already noticed someone publish one issue that library not available after April CU upgrade. Since Service Pack 1 for SharePoint is right around the corner. We may exam the release note before jump to this CU upgrade this time as Dan Holme described. In addition, there are many features will be introduced in SP1. See blog for details.

Thursday, April 28, 2011

Tips and tricks for Site Recycle Bin (Previous Site Deletion Capture) on SharePoint 2010

The Microsoft IT SharePoint 2010 Site Recycle Bin previous named Site Delete Capture tool has been released from CodePlex. It  that has been has been heavily used on SharePoint 2007 and a recommended tool for SharePoint Administrators by the IT Pro community. Most of the functions are identical to previous version and here are some tips and tricks to help you maximize the tool and avoid the pitfalls.

1. How to backup sites created form customized site definition using Recycle Bin tool?
By default this tool will only backup sites created form default Microsoft site templates. If you have sites created from customized site definitions, you need to staple both web and site scope features to ALL site definitions. If you add the following two line, ALL sites created from site definition will be captured.
  •  Goto 14 hive 14\TEMPLATE\FEATURES\SiteRecycleBinDeleteFeatureStapling open FeatureStapling.xml file and add the below entry
   <FeatureSiteTemplateAssociation Id="78B263D4-FF62-415e-B609-F01B06FA54E0" TemplateName="GLOBAL" />
  • Goto 14 hive 14\TEMPLATE\FEATURES\SiteRecycleBinSiteFeatureStapling\FeatureStapling and open FeatureStapling.xml file and add the below entry
   <FeatureSiteTemplateAssociation Id="78B94E15-23CE-43f9-8036-BABD847497D1" TemplateName="GLOBAL" />

2. How can we backup the sites already existing on SharePoint 2010 before the Recycle Bin tool installed?

You do not need to do anything. By default the deployment of this solution will activate the site feature and site collection on ALL existing sites on the farm. Here are the powershell command.

Install-SPSolution -Identity "SharePoint Site Recycle Bin.wsp" -GACDeployment
install-SPFeature -path "SiteRecycleBinSiteFeatureStapling\feature.xml" -force -confirm: $false  
install-SPFeature -path "SiteRecycleBinDeleteFeatureStapling\feature.xml" -force -confirm: $false 

As a result, you do not need to manually enable the features to make it affective. Cool!

3. Will Recycle Bin tool backup sites created form Fab 40 templates?
Yes. 2007 version described previously will not backup Fab 40 sites. However, new version will backup fab 40 sites as long as you add GLOBAL template in the feature stapling as described in #1. We have tested it with 12 different templates that were deployed as wsp on 2010.

4. Will Recycle Bin tool backup sub sites created form sandbox solution templates?
Unfortunately, this tool will NOT backup any sub sites created form templates user saved to templates and then uploaded to the solution gallery. When you check the site created from the saved template, features are activated and the site could be backed up using backup stsadm or powershell. It seems like this is the limitation for this tool. You could refer other blog on the ways to create sites using saved templates.

5.  Will Recycle Bin tool backup sub sites created form farm site templates?
As we described before, you could save the site to a template and deploy it to different farm as global farm based site template. So far so good. However, we found that the sites crated from this type of template could NOT be backed up by Site Recycle Bin. As a result, there is a risk those sites will not be easily recovered.

This is same as item #4, when you check the site created from the saved template, features are activated and the site could be backed up using backup stsadm or powershell.

6. Can we restore the site into the same content DB?
One of my college tested this and confirmed you could not backup the original site into the same content DB where site got deleted. You should be aware this when you backup the site.


7. What is Recycle Bin Backup Share size you should prepare
The answer depends on the governance policy and the SharePoint usage. You should answer the following questions before making the decision.
  • Size of active used sites and growth rate
  • Frequency of users will delete the site collection or sites based on previous experience
  • Size of the each site collections you setup that is depends on your quota setup
  • How long will backup the deleted sites
By answering these questions based on company's policy if there is any, you could calculate the necessary size needed. In normal case, we setup small size and monitor the deleted site.

8. How to resolve "The security validation for this page is invalid Microsoft.SharePoint.SPException" when activating feature 'SiteRecycleBinSiteFeature'?
Please see solution published in http://sharepointconnoisseur.blogspot.com/2011/05/security-validation-for-this-page-is.html for details.

Since Site Recycle Bin tool is using SharePoint stsadm backup command as internal mechanism to backup the sites, you will restore the site same as stsadm restore. You will noticed everything will keep same except the site collection GUID is different. You could refer to other blogs on the difference between backup/restore and export/import of the sites.

Tuesday, April 26, 2011

“Save Conflict" error when creating list or document library with "List Added Event Handler"

After adding "List Added Event Handler" to our SharePoint 2010 feature to update the list properties after listed created, we run into major issue during any list or document library creation by choosing below templates. The issue is we are getting "Save conflict" unexpected error. It is not consistent but happens much more frequently on “Calendar list”. The following list template will have such issue.
  • Document library
  • Form library
  • Wiki page library
  • Picture Library
  • Reports library
  • Calendar list


Users will get the error as indicated int he screen shot.

The error log is identical to the error people reported.

Microsoft.SharePoint.SPException: Save Conflict
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.



This is a very typical error occurs in SharePoint 2007 for asynchronous event handler. Due to SharePoint and the event receiver code trying to update the item at the same time. After debugging this issue and working with Microsoft, we have finally resolved it on SharePoint 2010. Here are the three changes you should try.

1.  Disable Event Firing when update the list. Please note this.EnableEventFiring() has been deprecated and the code for SharePoint 2010 is:
     EventFiringEnabled = false; 
     // Business logic here  
     EventFiringEnabled = true;

2. Use new SPWeb object for each list modification. The code should look like this if you apply #1 and #2 roles.

try
{
       // Use new SPWeb object for each list modification.
       SPWeb web = null;
       base.ListAdded(properties);

       //Disable Event Firing when update the list
       EventFiringEnabled = false;  
       properties.List.ParentWeb.AllowUnsafeUpdates = true;
       web = properties.Web.Site.OpenWeb(properties.Web.ID);
       SPList list = properties.List;
       list.Title = "Correlation Id- Save Conflict error";
       // Other actions to add policy to the list
       // Action to add tagging to the content
       list.Update();
       properties.List.ParentWeb.AllowUnsafeUpdates = false;
       EventFiringEnabled = true;
}


3. If you still have save conflict issues like we did, in SharePoint 2010, we have the option to make these kind of events Synchronous by adding this in the Element.xml file of the event receiver while we are registering it.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers >
      <Receiver>
        <Name>MyCompanyListReceiverListAdded</Name>
        <Type>ListAdded</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>mycompany.com.sp.features.mycompanyListReceiver.mycompanyListReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
        <Synchronization>Synchronous</Synchronization>
      </Receiver>
  </Receivers>
</Elements>


After doing adding these changes, we are able to resolve the issue and enjoy the list event.

Thursday, April 21, 2011

How to resolve (401) Unauthorized error for SharePoint web service call from Infopath Webbased form?

We run into an exception when calling OoB list web services from Infopath Webbased form on SharePoint 2010. The exception is "The remote server returned an error: (401) Unauthorized. The remote server returned an error: (401) Unauthorized."

We have NetScaler as load balance in front of multiple IIS servers and we have VIP setup for the Webapps. Users http://SharePointWebApp. However, if the web service is invoked from each individual server such as from the Infopath Webbased form, it generates exception described above. We had this issue before on SharePoint  2007 over two years ago, I though it would be beneficial to record the solution so we will not forget in the future.

There are many possibilities that could cause (401) Unauthorized error. The two major issues if you are using load balancer with multiple IIS servers and setup the alias or VIP for the webapp are authentication loop back issue and load balancer did not return the local host IP issue. You need to fix both of them in order to make web service calls successfully. Here are the procedure to fix them.


1. Authentication loop back issue
The cause was .net 3.5 sp1 - the fix for me was to add a key to the registry to disable authentication double look up. The way to do it is to set the DisableLoopbackCheck registry entry in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa registry subkey to 1.

To set the DisableLoopbackCheck registry entry to 1, follow these steps on the client computer:
  • Click Start, click Run, type regedit, and then click OK.
  • Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
  • Right-click Lsa, point to New, and then click DWORD Value.
  • Type DisableLoopbackCheck, and then press ENTER.
  • Right-click DisableLoopbackCheck, and then click Modify.
  • In the Value data box, type 1, and then click OK.
  • Exit Registry Editor.
  • Restart the computer
You could refer to Microsoft link for details and some other links for such solution. There is another KB article on the loop back issue.


2. Load balancer web service call does not return back to the local server. It seems like the web service call fails if the call initialized from one of the servers behind the Load balancer but pointing to web service using VIP alias.

Here are the steps to find the IPs and fix this.

First, you would need to identify the IP for Webapp VIP alias. If your site URL for the is http://SharePointWebApp, you could identify the IP for it from the IIS server using the command and the IP is 22.44.555.66.

C:\ >ping SharePointWebApp
Pinging sharepoinwebapp.compony.com [22.44.555.66] with 32 bytes of data:
Reply from 22.44.555.66: bytes=32 time=1ms TTL=255


Second, find the IP for the IIS server behind the load balancer using the command ipconfig like below and the IP is 77.33.99.44.


C:\Users\osstst1>ipconfig /all
Windows IP Configuration
   Host Name . . . . . . . . . . . . : xxxxxxxxx
   Primary Dns Suffix  . . . . . . . : na.compony.com
   Node Type . . . . . . . . . . . . : Peer-Peer
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : compony.com

   ......
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 77.33.99.44(Preferred)


Third, you added one line entry into host file that is located at C:\Windows\System32\drivers\etc\host. Add one additional line like:

77.33.99.44       SharePointWebApp

Forth, you flush the DNS Resolver Cache using command and verify the WebApp VIP IP original value 22.44.555.66 returned by ping that will changed to local IIS server IP that is 77.33.99.44.
C:\>ipconfig /flushdns 
C:\ >ping SharePointWebApp
Pinging sharepoinwebapp.compony.com [77.33.99.44] with 32 bytes of data:
Reply from 22.44.555.66: bytes=32 time=1ms TTL=255


Now, the web service called by Infopath Webbased form on SharePointIIS server will not go back to the load balancer. It will call web service hosted by the same host server.

By changing these two settings, you should be able to resolve (401) Unauthorized error.

Good luck.