Monday, August 6, 2012

Installing Standalone SharePoint 2013 Preview on Virtualised Windows Server 2012 RC with SQL Server Express 2012

Over the weekend I decided to try the new SharePoint 2013 Preview. According to http://technet.microsoft.com/en-us/library/cc262485(v=office.15).aspx the minimum hardware requirement is
Single server with a built-in database or single server that uses SQL Server
Development or evaluation installation of SharePoint Foundation 2013 Preview
8 GB
64-bit, 4 cores
80 GB for system drive

Unfortunately the only hardware available to me is a 64-bit, 4 cores machine with 8GB RAM and since I am planning to run it on a virtual machine I can’t assign the whole resource to the VM
So I ended up allocating 5 GB and 3 cores to the virtual machine. So far the performance is okay (not great but acceptable).

So these are the step by step instructions on how to do it:
1. Create a new virtual machine with 5 GB and 3 cores.
2. Make sure you select "Accelerate 3D graphics".

3. Put the Windows Server 2012 iso location in the Installer disc image file.
4. Windows Server 2012 is not one of the options in the available operating system version so I used Windows Server 2008 R2 x64 instead.
 
5. Set the maximum disk size and whether you want to split into multiple files or keep it in a single file.
6. Setup the Network Adapter to use NAT: Used to share the host’s IP address. This is important because SharePoint 2013 requires an Active Directory (it will not work with just workgroup).
 
7. Let the installer installs Windows Server 2012.
8. Next what you need to do is add Active Directory Domain Services role and DNS Server role (AD DS depends on this role) plus .NET Framework 3.5 Features (needed by SQL 2012 Express). When installing DNS server you have to have your VM connected to the internet.
9. This can be done by going to Server manager -> Add roles and features
 
 
10. Then you have to promote the current server into Domain Name Server (make sure the administrator’s password is not blank, not your password).
11. Install the SQL Server 2012 Express.
12. Install the SP Pre-Requisite
13. Install SharePoint Server 2013 Preview and run the Product Configuration Wizard.
14. All 3 steps above should be straight forward. The key things are to add the active directory domain services role first and to install .NET Framework 3.5 before installing SQL Server 2012 Express.

Screenshots from SharePoint 2013:



I would probably update this post soon (when SharePoint 2013 finally released).
Have a great day.

Evan 

Thursday, May 3, 2012

My Simple Rules for SharePoint 2010 Caching


I am always a fan and a true believer of caching.
So what is a cache?
A temporary storage area where frequently used data can be stored for rapid access.

Based on my experience developing and configuring SharePoint 2010 solution for many clients I have a few simple rules about caching in SharePoint 2010. The 4 different types of caching available in SharePoint 2010 and my simple rules for them:

1. Object Caching
- To activate: Site Actions – Site Settings – Site collection object cache.
- Default max cache size: 100 MB.
- Optimum cache size: depends on the server specification but I reckon 1 GB is the sweet spot.
- Default Duration: 180 seconds.
- Optimum duration: depends on the business but I reckon between 15-20 minutes is the sweet spot.

2. Output Caching
- To activate: Site Actions – Site Settings – Site collection output cache.
- Available profiles: Site Actions – Site Settings – Site collection cache profiles.
- Public Internet (Anonymous) profile:
     Default duration: 180 seconds.
     Optimum duration: depends on the business but I believe between 30-60 minutes.
     Default cacheability: ServerAndPrivate.
     Optimum cacheability: Public -> it means “always cache it if you can” in any server possible.
- Intranet (Collaboration Site) profile:
     Default duration: 180 seconds.
     Optimum duration: depends on the business but I believe around 15 minutes.
     Default cacheability: ServerAndPrivate.
     Optimum cacheability: Public -> it means “always cache it if you can” in any server possible.

3. Blob Caching
- Stores frequently used files in the disk instead of database.
- The setting is in the web.config.

4. HttpRunTime Cache
- General IIS cache used by ASP .NET.
- Use this caching method whenever possible.
- Generally used for 3rd party services (Google Weather, Yahoo Finance and other services).
- It is also very useful to server content / list items which appear the same to everyone (such as utility links, reusable content viewer, etc).

Wednesday, August 24, 2011

SiteMap Providers static property issue


There is a time when we need to modify a sitemap provider object and then use it.

Scenario:
We need to build a sub navigation control but we don’t want to include pages

Example code:
PortalSiteMapProvider sitemapprovider =                    (PortalSiteMapProvider)SiteMap.Providers["CurrentNavSiteMapProvider"];
               
sitemapprovider.IncludePages = PortalSiteMapProvider.IncludeOption.Never;

The problem with the code above is:
1.       The SiteMap.Providers property is a static property. It returns the object reference to the single instance of the provider.
2.       Modifying the object permanently changes the value.

One way to avoid this issue is to save the value of the property temporarily and then rollback the value back.

Example code:
ortalSiteMapProvider sitemapprovider =
(PortalSiteMapProvider)SiteMap.Providers["CurrentNavSiteMapProvider"];
               
var tempIncludePages = sitemapprovider.IncludePages;

sitemapprovider.IncludePages = PortalSiteMapProvider.IncludeOption.Never;

sitemapprovider.IncludePages = tempIncludePages;

This simple workaround seems to work properly.

Hope this helps J

Wednesday, June 15, 2011

SharePoint 2010 Broken Page Menu Ribbon (Keep on Loading)

My ribbon page menu suddenly stopped working this afternoon. Clicking the page menu gave me the loading icon without any progress.



After some investigation I found out that the code which I added this morning is the problem.

        String.prototype.startsWith = function(str){
            return (this.toLowerCase().indexOf(str) == 0);
        }

Apparently “startsWith” is a reserved word so changing the function name into another name fixed the problem.

A friend of mine told me “SharePoint keeps you young by forcing you to learn new stuffs almost everyday”.
And he is right J


Monday, May 30, 2011

SharePoint 2010 Fields or Columns Naming Problem

I was hammered by a bug found by our client. They were trying to reorder fields of a custom list and for some reason SharePoint threw the following error.


After hours and hours of investigation I finally found out what the problem is.
There were spaces in the name property of the fields. In theory SharePoint should have converted the spaces into “_x0020_” and everything should be okay. However reordering fields of this custom list produces the error above.

SharePoint does not like:
  <Field ID="{176C37CB-99E2-4730-8B61-C994151094B8}" Name="Field 1 With Spaces" StaticName="Field1WithSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 1 With Spaces" Type="Note" NumLines="10" RichText="TRUE" Description="Field 1 With Spaces" RichTextMode="FullHtml"></Field>
  <Field ID="{DC7451BC-BF4C-43F1-B443-E297190C008A}" Name="Field 2 With Spaces" StaticName="Field2WithSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 2 With Spaces" Type="Note" NumLines="10" Description="Field 2 With Spaces" RichText="TRUE" RichTextMode="FullHtml" />

But it likes:
  <Field ID="{176C37CB-99E2-4730-8B61-C994151094B8}" Name="Field1WithoutSpaces" StaticName="Field1WithoutSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 1 Without Spaces" Type="Note" NumLines="10" RichText="TRUE" Description="Field 1 Without Spaces" RichTextMode="FullHtml"></Field>
  <Field ID="{DC7451BC-BF4C-43F1-B443-E297190C008A}" Name="Field2WithoutSpaces" StaticName="Field2WithoutSpaces" SourceID="http://schemas.microsoft.com/sharepoint/v3" Group="FESA.SPS2010.Internet" DisplayName="Field 2 Without Spaces" Type="Note" NumLines="10" Description="Field 2 Without Spaces" RichText="TRUE" RichTextMode="FullHtml" />

So the lesson is not to have any spaces (or any invalid characters) in the name of the Fields.

Have a great day everyone.

Wednesday, April 20, 2011

Robots.txt prevents SharePoint 2010 search crawler from crawling sites

As per our operation manager’s request I added robots.txt on our preview server to prevent Google’s bot or Bing’s bot from indexing our client’s preview sites.

Original robots.txt:
User-agent: *
Disallow: /

Effectively it should stop all legitimate bots from indexing preview sites. However this also stopped SharePoint 2010’s search crawler from crawling the sites. Any full crawl gave me 0 results.

The solution is to allow SharePoint 2010’s search crawler but to disallow other bots.  Now how do we find the user agent string for SharePoint 2010’s crawler?
If you go to Registry Editor and open the following:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Global\Gathering Manager\UserAgent
You will find the UserAgent string used by SharePoint 2010’s crawler.
So all I had to do was edit my robots.txt to allow that particular user agent to index our SharePoint 2010 sites.

Updated robots.txt:
User-agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT; MS Search 6.0 Robot)
Allow: /
User-agent: *
Disallow: /

Hope this helps :)

Tuesday, April 19, 2011

Updating external content type for SharePoint 2010 Business Connectivity Service

Our client submitted a request to update their existing External Content Type used for BCS. The request was so simple: rename Address field into Department and add 1 extra field. I thought this should be easy.

So I updated the employee model and redeployed the solution. But for some reason the changes didn’t get reflected in the content type. I have tried everything from resetting IIS, clean solution, rebuild solution, even copy and paste the dll directly to the GAC without any result.

After further investigation I found out that the type descriptor (which you can see from BDC explorer or by opening the bdcm file in notepad) are not automatically updated.
So that is the lesson, the type descriptors needs to be updated manually.


Wednesday, March 30, 2011

Printing in SharePoint 2010 without header, navigation and some other elements

I am pretty sure most of you know about this but perhaps just never thought about it.

Being able to print is one of the most essential requirements of a website. Eventually user want to be able to print the content of a page but perhaps without the header, navigation or some other SharePoint’s element.

This is one simple trick that does the job for me on hiding those elements.

/* Print styles */
@media print
{
    .contentSkip, .s4-notdlg,
    #stuffNotToBePrinted, #s4-ribbonrow, .header, #header
    {
        display: none !important;
    }
}

Just add the above styling to your style sheet (obviously you need to add the things you want to hide to the above css style) and those elements should be hidden.

Have a nice day J

Tuesday, February 15, 2011

Disposing SPSite and SPWeb

Most of the time when we are working with a site or a web we would put a using statement such as these:
using (SPSite siteCollection = new SPSite("http://evan.local"))
{
    // Code here
}
using (web = site.OpenWeb("search"))
{
    // Code here
}
The reason is so that site collection / the web are disposed properly.

However trying to do similar thing in:
using (SPSite site = SPContext.Current.Site)
{
       Code here
}
using (SPWeb web = site.RootWeb)
{
       Code here
}

Will give you the following error in the log:

Unexpected    Detected use of SPRequest for previously closed SPWeb object.  Please close SPWeb objects when you are done with all objects obtained from them, but not before.


The reason is the SPContext (together with the site collection/web property in the object) will be automatically disposed when SharePoint finish with it. By putting them into the “using” statement, we are actually disposing the object when they are still being used.

So the conclusion:
If you are opening a site / a web then use “using” statement;
If you are utilising a site/web object from a property of the SPContext object then please do not use “using” statement.

Have a great day everyone J

Wednesday, February 2, 2011

Using a 3rd party control in SharePoint 2010

In this example I was trying to use Recaptcha in one of my custom SharePoint Page.

In normal ASP .Net registering the following TagPrefix should be enough:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

Then I should be able to use the control just like this:
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="SOME_PUBLIC_KEY" PrivateKey="SOME_PRIVATE_KEY" />

However SharePoint did not like it, instead I was getting the following error:
System.IO.FileNotFoundException: Could not load file or assembly 'Recaptcha' or one of its dependencies. The system cannot find the file specified.    at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)     at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)     at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)     at System.Reflection.Assembly.Load(String assemblyString)     at System.Web.Configuration.CompilationSection.LoadAssembly(String asse...      a475e341-2fe9-435c-916f-189bee006e81

The solution is to register recaptcha using the fully qualified name including the PublicKeyToken like this:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha, Version=1.0.5.0, Culture=Neutral, PublicKeyToken=9afc4d65b28c38c2" %>

Hope this helps.

Wednesday, January 19, 2011

Sitefinity 3.7 newsletter module error

This morning one of our clients reported that clicking on the Newsletter module tab in the Sitefinity’s administration produces an error.

The reason is Sitefinity automatically generates service assembly in /Sitefinity/ServiceAssemblies/3889AC4AF542BAC3C62ABB154E78FEA8.dll

This dll depends on the host machine and Sitefinity’s version among other things.
So if you copy the site from other place then most likely you will get the error when trying to access the newsletter module.

If you search Sitefinity’s forum you will find that deleting the dll should force Sitefinity to regenerate the dll. However sometimes you still get the error even after deleting the dll.
One thing that I found useful is dropping the newly regenerated dll into the bin folder. It always fixes the problem for me.


Thursday, December 23, 2010

SharePoint 2010 Limitations

Rodney, one of my colleague shared interesting facts about SharePoint 2010 limitations today.

There are a few “interesting” limitations.

Limit
Maximum value
Limit type
Notes
List row size
8,000 bytes per row
Boundary
Each list or library item can only occupy 8000 bytes in total in the database. 256 bytes are reserved for built-in columns, which leaves 7744 bytes for end-user columns. For details on how much space each kind of field consumes, see Column limits.
Items
30,000,000 per list
Supported
You can create very large lists using standard views, site hierarchies, and metadata navigation. This value may vary depending on the number of columns in the list and the usage of the list.
List view lookup threshold
8 join operations per query
Threshold
Specifies the maximum number of joins allowed per query, such as those based on lookup, person/group, or workflow status columns. If the query uses more than eight joins, the operation is blocked. This does not apply to single item operations. When using the maximal view via the object model (by not specifying any view fields), SharePoint will return up to the first eight lookups.


Have a great day J

Monday, December 20, 2010

Using Fluent NHibernate in SharePoint 2010

Most of the time when developing with SharePoint 2010 we don’t have to use any ORM mapping because SharePoint’s API take care of 99% of our needs. Today I had to use Business Connectivity Services to expose data in a third party database as External List.

When defining Business Connectivity Model in SharePoint project we have to write (at least) our own ReadList and ReadItem methods.

My implementation of ReadList and ReadItem were pretty simple:

        public static MyEntity ReadItem(string id)
        {
            var session = SessionSource.Current.GetSession();
            var repository = new Repository<MyEntity>(session);

            return repository.GetById(id).ToEntity();
        }

        public static IEnumerable<MyEntity> ReadList()
        {
            var session = SessionSource.Current.GetSession();
            var repository = new Repository<DomainObject>(session);
            var results = repository.ListAll();
            return results.Select(x => x.ToEntity()).ToList();
        }

Those 2 methods worked fine in the Unit Test. However (as usual) when running in SharePoint’s environment they fell apart.
After a lot of hours in debugging finally I managed to make they work.

These are a few things you might want to check when using Fluent NHibernate with SharePoint 2010:

1. Make sure you include ALL dlls which came with Fluent NHibernate in the package with GlobalAssemblyCache as the target deployment (Business Connectivity Model will have to be deployed as a farm solution).














2. Add qualifyAssembly tags for all those dlls to your web config to tell NHibernate to load those assemblies from the GAC instead of the bin folder.







After completing those 2 steps my ReadList and ReadItem work as expected J
Hope this helps J

Thursday, December 16, 2010

SharePoint 2010 and .NET 4.0

This morning, I tried to change the target framework of my SharePoint 2010 projects to use .NET 4.0; however the .NET Framework 4.0 option was not visible for some reason.


Clicking on the “Install other frameworks…” brought my IE to the Microsoft .NET 4 framework download page (I ended up downloading the .NET 4.0 and repair my installation). However after rebooted the server, the option to target .NET 4.0 still was still missing.

A quick Google search told me that SharePoint 2010 does not support .NET 4. It runs on .NET 3.5 only (at least not yet). Surely there will be a service pack to tackle this issue in the near future.

So a tip for all of you who are planning to use .NET 4.0 for your SharePoint’s development: don’t do it (not yet).

Have nice Thursday J

Evan Putranto

Tuesday, December 14, 2010

Visual Studio 2010 debugger not stopping on SharePoint 2010 breakpoints

One of my work colleagues shared something which I think is very useful today, so I thought I should share it in here.

Occasionally, when trying to debug SharePoint 2010 codes by attaching the debugger to the w3wp.exe process, the debugger does not stop on any break points. The problem is seems to be due to Visual Studio 2010 and the version of .NET framework used.

When attaching the debugger, Visual studio by default automatically determines the code types to debug (Managed, Native, Script, T-SQL etc). With Visual Studio 2010 however, there’s now 2 Managed code types (v2.0, v1.1, v1.0) and (v4.0), because we are still using .NET 3.5 occasionally Visual Studio gets confused and automatically determines 2.0 managed code as 4.0 managed code. This causes the debugger to be successfully attached but not to stop in any breakpoints.

By setting Visual Studio to always manually debug on Managed (v2.0, v1.1, v1.0) and T-SQL seems to fix the problem. It’s been working consistently so far.

Screenshot:

Visual Studio 2010 Debugger

Have a nice day :)

Evan Putranto

Thursday, December 9, 2010

HttpRunTime.Cache & ReaderWriterLock


Yesterday there we had a big problem with one of our client website. It was using 100% CPU and chewing all the memory it can get. Yes it is a retail website (a lot of visitors visiting the website every second). However it still shouldn’t bring all other website in the server down and unresponsive.

After some investigation I found out that the cache manager (where we use HttpRunTime.Cache) uses a lock during insert and remove item method call. It should use a lock because there will be multiple request happening at the same time. If we don’t use any lock some of the data returned to the browser might be corrupted.

However because we were using a normal lock what happen was all the request queuing to get a slice of time in the cache even when it was only trying to read. As more visitors visiting the website the longer the queue and the more memory they use.

I remember I used ReaderWriterLock in the past and I found it very useful especially in the situation like this. So I decided to change the lock to use ReaderWriterLock. And wallah it worked like magic and instantaneous drop in the memory usage and CPU time.

So this is my first tip: Cache & ReaderWriterLock are best friends J
Have a good day.