Friday, December 23, 2011

How to disable or hide the “All Users” from people picker

When we have multiple tenants in sharepoint 2010 and have different identity provider, in people picker you might see all the trusted provider being listed in the result of "All Users".


We can disable the “All Users” from people picker via the below powershell script.

$cpm = Get-SPClaimProviderManager
$au = get-spclaimprovider –identity "AllUsers"
$au.IsEnabled = $false
$cpm.Update()

Tuesday, August 9, 2011

MOSS - Custom error page

In MOSS 2007, how will you display a custom error page?
By using the simple ASP.net way of setting <custom errors="On" defaultRedirect="errorURL"/> won't work in sharepoint

You basically need to write a custom HTTPModule and add the entries in the web.config of your webapplication.

Here is a sample for your reference.

public class MyError : IHttpModule
        {
            const string errorUrl = "/_layouts/CustomErrorPage/Error.aspx";

            public void Dispose()
            {
                //dispose your objects
            }

            public void Init(HttpApplication context)
            {
                context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);

            }
            void context_PreRequestHandlerExecute(object sender, EventArgs e)
            {
                Page page = HttpContext.Current.CurrentHandler as Page;
                if (page != null)
                {

                    page.Error += new EventHandler(page_Error);
                }
            }


            void page_Error(object sender, EventArgs e)
            {
                Page page = sender as Page;
               
                    string strWebURL = SPContext.Current.Web.Url;
                    HttpContext.Current.Response.Write("<script type=\"text/javascript\">window.location = \"" + errorUrl + "\"</script>");
                    HttpContext.Current.Response.Flush();
               
            }
        }

Hope you all know how to deploy it. If you need steps on how to deploy, please feel free to ask.


Happy Coding :)


Saturday, August 6, 2011

SPFile.Versions.Count & SPListItem.Versions.Count

There is always a confusion between SPFile.Versions.Count & SPListItem.Versions.Count, as to which one to use and what is its purpose.
  

SPListItem.Versions.Count is always 1 more than SPFile.Versions.Count. The reason is SPFile consider the latest version as the current version and therefore does not include this in its version collection.

Thus, SPListItem.Versions.Count[1]  is equal to SPListItem.SPFile.Versions.Count[0].

if you go to  version history of a document , you will get a count equal to SPListItem.Versions.Count

Thus SPListItem.Versions.Count will give you, an exact version count of a document.