Tuesday, December 27, 2011

Estimate content database storage - SharePoint 2010

This article describes how to plan for and configure the storage and Microsoft SQL Server database tier in a SharePoint 2010 environment.
The capacity planning information in this article provides guidelines for you to use in your planning. It is based on testing performed at Microsoft on live properties. However, your results may vary based on the equipment you use and the features and functionality that you implement for your sites.
This article assumes that you are familiar with the concepts presented in Capacity management and sizing for SharePoint Server 2010.
Estimate content database storage
The following process describes how to approximately estimate the storage required for content databases, without considering log files:
1.       Calculate the expected number of documents. This value is referred to as D in the formula.
2.       Estimate the average size of the documents that you will be storing. This value is referred to as S in the formula.
3.       Estimate the number of list items in the environment. This value is referred to as L in the formula. List items are more difficult to estimate than documents.
4.       Determine the approximate number of versions. This value is referred to as V in the formula. The value of V must be above zero.
5.       Use the following formula to estimate the size of your content databases:
Database size = ((D × V) × S) + (10 KB × (L + (V × D)))
The value of 10 KB in the formula is a constant that roughly estimates the amount of metadata required by SharePoint Server 2010. If your system requires significant use of metadata, you may want to increase this constant.
As an example, if you were to use the formula to estimate the amount of storage space required for the data files for a content database in a collaboration environment with the following characteristics, you would need approximately 105 GB.


Input
Value
Number of documents (D)
200,000
Calculated by assuming 10,000 users times 20 documents
Average size of documents (S)
250 KB
List items (L)
600,000
Number of non-current versions (V)
2
Assuming that the maximum versions allowed is 10


Database size = (((200,000 x 2)) × 250) + ((10 KB × (600,000 + (200,000 x 2))) = 110,000,000 KB or 105 GB

Download the Excel sheet for easy calculations.

Saturday, November 26, 2011

Check Current User Gorup In SharePoint Object Model


To manage permission we create Groups in SharePoint. In Custom SharePoint application or webpart, we have to check user permissions or may have activate different  functionality.

For that We need to check Current User Group..

Here is a function that will return true/false by providing Group Name!

private bool IsCurrentUserMemberOfGroup(string GroupName)
        {
            try
            {
              return SPContext.Current.Web.IsCurrentUserMemberOfGroup(SPContext.Current.Web.Groups[GroupName].ID);               
            }
            catch (Exception)
            {
                return false;
            }
        }


You may provide web object for performance tuning.

Friday, November 4, 2011

Remove Lookup Hyperlink from SharePoint List view using JQuery

When you use lookup to the list automatically SharePoint give link to the lookup item on list view.
Check it out….
Lookup column with Hyperlinks
But many times, we don’t want  those Hyperlinks on the list view, as we can remove it from SharePoint Designer but it’s a hectic task.
Simply add JQuery  to remove those Hyperlinks.
First, get the URL of the link using Developer tool of IE or Firebug of Firefox browser. we are going to some part of URL in the below code.

Get URL using Developer tool of IE


Then copy following JQuery code to the HTML form WebPart on list view.

Jquery For MOSS 2007/WSS 3.0:


    
    

Note: Change highlighted text as per your context.
Jquery For SharePoint 2010/SharePoint Foundation 2010:





Note: Change highlighted text as per your context.

If View is Grouped, set list view setting "By default, show groupings:" to  Expanded


List View setting: Make sure that By default, show groupings: Expanded

List view with removed hyperlinks to Lookup columns:

Live simple!

How to rename the list view column name using JavaScript

We can change column name from JavaScript, it will not affect your existing functionality or custom code and also no need to change column name from SharePoint Designer as it is a troublesome task.
Follow this steps….
1. Get column Id using Developer tool of IE or Firbug of Firefox.
Get Column ID using Developer tool of IE

2. Add following JavaScript in HTML form web part on the list view.
<script type="text/javascript">
//This script is developed by Amit Phule # http://amitphule.blogspot.com/
 _spBodyOnLoadFunctionNames.push("ChangeColumnName"); // Call ChangeColumnName function on PageLoad
        function ChangeColumnName() {
            RenameColumn('diidSortAuthor', 'Author'); //Provide Column ID and New Column name
        }
        function RenameColumn(colID, NewHeader) {
            try {
                document.getElementById(colID).innerHTML = NewHeader; //Change Header Name
                document.getElementById(colID).title = "Sort by " + NewHeader; // Change Tooltip value
            }
            catch (err) {
                alert('Invalid Column ID:' + colID);
            }
        }
 </script>

Old column Name:
New Column Name:


Live simple !

Monday, October 31, 2011

Hiding Group Headers from SharePoint List View



We can hide the Group name in out of the box list view using JavaScript.
Grouped List View before adding JavaScript:


JavaScript (MOSS 2007/WSS 3.0):
<script type="text/javascript" language="javascript">
        _spBodyOnLoadFunctionNames.push("HideHeaders");

        function HideHeaders() {
            var elements = getElementsByClassName(document, "td", "ms-gb");
            var elem;
            for (var i = 0; i < elements.length; i++) {
                elem = elements[i];
                elem.childNodes[3].style.display = "none";
                elem.childNodes[4].nodeValue = elem.childNodes[4].nodeValue.replace(':', '');
            }

            elements = getElementsByClassName(document, "td", "ms-gb2");

            for (var i = 0; i < elements.length; i++) {
                elem = elements[i];
                elem.childNodes[3].style.display = "none";
                elem.childNodes[4].nodeValue = elem.childNodes[4].nodeValue.replace(':', '');
            }
        }

        function getElementsByClassName(oElm, strTagName, strClassName) {
            var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
            var arrReturnElements = new Array();
            strClassName = strClassName.replace(/\-/g, "\\-");
            var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
            var oElement;
            for (var i = 0; i < arrElements.length; i++) {
                oElement = arrElements[i];
                if (oRegExp.test(oElement.className)) {
                    arrReturnElements.push(oElement);
                }
            }
            return (arrReturnElements)
        }
    </script>
JavaScript (SharePoint 2010/SharePoint Foundation 2010):
<script type="text/javascript" language="javascript">
        _spBodyOnLoadFunctionNames.push("HideHeaders");

        function HideHeaders() {
            var elements = getElementsByClassName(document, "td", "ms-gb");
            var elem;
            for (var i = 0; i < elements.length; i++) {
                elem = elements[i];
                elem.childNodes[0].childNodes[1].nodeValue = "";
                elem.childNodes[1].nodeValue = elem.childNodes[1].nodeValue.replace(':', '');
            }

            elements = getElementsByClassName(document, "td", "ms-gb2");

            for (var i = 0; i < elements.length; i++) {
                elem = elements[i];
                elem.childNodes[1].childNodes[1].nodeValue = "";                elem.childNodes[2].nodeValue = elem.childNodes[2].nodeValue.replace(':', '');
            }
        }

        function getElementsByClassName(oElm, strTagName, strClassName) {
            var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
            var arrReturnElements = new Array();
            strClassName = strClassName.replace(/\-/g, "\\-");
            var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
            var oElement;
            for (var i = 0; i < arrElements.length; i++) {
                oElement = arrElements[i];
                if (oRegExp.test(oElement.className)) {
                    arrReturnElements.push(oElement);
                }
            }
            return (arrReturnElements)
        }
    </script>


Grouped List View after adding JavaScript:

Enjoy!

Wednesday, October 12, 2011

How to show days count after created date of Item in SharePoint list View

There are many posts showing date difference from today's date, but not a exactly the working solution is provided.
I have created the column that will show days count between Today's date and Created Date. and this column is update automatically.
For this I have created one calculated column and added simple JavaScript on the SharePoint List view.
Step 1:
Create new calculated column in the list and give formula as follows

="<DIV ID='CreatedDate'>"&TEXT(Created,"MM/dd/yyyy")&"</DIV>"

Step 2:
Add Form Webpart(MOSS 2007) or HTML Form webpart(SharePoint 2010) on the view and  add below JavaScript in it.
<script type="text/javascript">   
// Script created by Amit Phule
// Taken reference from Christophe@PathToSharePoint.com post
  
        var theTDs = document.getElementsByTagName("TD");
        var i = 0;
        var TDContent = " ";
        while (i < theTDs.length) {
            try {
                TDContent = theTDs[i].innerText || theTDs[i].textContent;
                if ((TDContent.indexOf("<DIV ID='CreatedDate'") == 0) && (TDContent.indexOf("</DIV>") >= 0)) {
                    theTDs[i].innerHTML = getDateDiff(TDContent.replace('</DIV>', '').replace("<DIV ID='CreatedDate'>", ''));
                }
            }
            catch (err) { }
            i = i + 1;
        }
      
        // ExpGroupRenderData overwrites the default SharePoint function.  This part is needed for collapsed groupings      
        function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
            var tbody = document.getElementById("tbod" + groupName + "_");
            var wrapDiv = document.createElement("DIV");
            wrapDiv.innerHTML = "<TABLE><TBODY id=\"tbod" + groupName + "_\" isLoaded=\"" + isLoaded + "\">" + htmlToRender + "</TBODY></TABLE>";
            var theTBODYTDs = wrapDiv.getElementsByTagName("TD"); var j = 0; var TDContent = " ";
            while (j < theTBODYTDs.length) {
                try {
                    TDContent = theTBODYTDs[j].innerText || theTBODYTDs[j].textContent;
                    if ((TDContent.indexOf("<DIV ID='CreatedDate'") == 0) && (TDContent.indexOf("</DIV>") >= 0)) {
                        theTBODYTDs[j].innerHTML = TDContent;
                    }
                }
                catch (err) { }
                j = j + 1;
            }
            tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild, tbody);
        }
        function getDateDiff(Date2) {         
            var days = 0;
            var difference = 0;
            Christmas = new Date(Date2);
            today = new Date();
            difference = today - Christmas;
            days = Math.round(difference / (1000 * 60 * 60 * 24));
          if(days!=0)
            days = days - 1;
            return days;
        }
    </script>


Screenshot:

Tuesday, October 11, 2011

Don't Show Missing Image Icon

Suppose you have html page that will display users profile with profile images and if image is not present, automatically missing image icon is appearing, it's looks unprofessional.
We can hide this icon or replace with the default image.
Simply Hide the missing image icon using Javascript:

<img id='ProfileImage' src='/images/1234.png' />

<script type="text/javascript">
var img = document.getElementById("ProfileImage");

img.onerror = function () { this.style.display = "none"; }
</script>

Thursday, October 6, 2011

Use Rich Textbox of SharePoint 2007 in a custom asp.net page or user control

Many times while creating Custom SharePoint Form using ASP.net you need RichTextBox.
In SharePoint Controls there is a InputFormTextBox control that can be used as a RichTextBox. It control give same functionality and user interface as in SharePoint.
Take a look.



1. Add following tag (If you not added before) to Register the SharePoint DLL in your custom page or user control.

<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

2. Add InputFormTextBox Control tag on the Page.
<SharePoint:InputFormTextBox runat="server" ID="TxtBody" ValidationGroup="CreateCase" Rows="8" Columns="140" RichText="true" RichTextMode="FullHtml" AllowHyperlink="true" TextMode="MultiLine" />

Enjoy!

Tuesday, September 27, 2011

Print Button on SharePoint Page


We can easly add print functionality on SharePoint Page. Just add following Javascript on the page (you can use HTML Form Webpart for adding javascript).

In Javascript i have used WebPartElementID="onetIDListForm" ; which is SharePoint Default ID of the Main contents.

JavaScript:

<script type="text/javascript" language="JavaScript">
//Controls which Web Part or zone to print 'TD ID'
var WebPartElementID = "onetIDListForm"; //SharePoint Main Content ID

//Function to print Web Part
function PrintArea()
{
var bolWebPartFound = false;
if (document.getElementById != null)
{
//Create html to print in new window
var PrintingHTML = '<HTML>\n<HEAD>\n';
//Take data from Head Tag

PrintingHTML += document.getElementsByTagName('head')[0].innerHTML;
PrintingHTML += '\n</HEAD>\n<BODY class="printSQS">\n';
var WebPartData = document.getElementById(WebPartElementID);
if (WebPartData != null)
{
PrintingHTML += WebPartData.innerHTML;
bolWebPartFound = true;
}
else
{
bolWebPartFound = false;
alert ('Cannot Find Web Part');
}
}
PrintingHTML += '\n</BODY>\n</HTML>';
//Open new window to print
if (bolWebPartFound)
{
var PrintingWindow = window.open("","PrintWebPart",
"toolbar,width=800,height=600,scrollbars,resizable,menubar");
PrintingWindow.document.open();
PrintingWindow.document.write(PrintingHTML);
PrintingWindow.document.close();
// Open Print Window
PrintingWindow.print();
}
}
</script>

HTML Code:

<input type="button" value="Print" onclick="javascript:void(PrintArea());return false;__doPostBack('btPrint','')" />

<a href="#" onclick="javascript:void(PrintArea());return false;__doPostBack('btPrint','')"  ><img src="/sites/aaa/PublishingImages/print.gif" border="0" complete="complete"/></a>


You can add html code any where on the page.

Thursday, August 25, 2011

Quick Notes: How to Detect the Installed Edition of SharePoint 2010

Many times it is required to know the current edition of SharePoint 2010 installed.
If the behavior of your custom application depends on the installed SKU of Microsoft SharePoint Server 2010, you can determine which SKU of SharePoint Server 2010 is installed locally by using the Power shell command and GUID of SharePoint 2010 Editions.
In this topic I will explain the how to get current edition of SharePoint 2010.
1.      You can get GUID of installed SharePoint 2010 from registory within the registry key HKLM\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\InstalledProducts.
2.      Or You can also use the PowerShell command get-spfarm | select Products to output GUIDs for the installed SKUs.
3.      As you get the GUID then you can check it with following table.
SharePoint 2010 Edition
GUID
SharePoint Foundation 2010
BEED1F75-C398-4447-AEF1-E66E1F0DF91E
Search Server Express 2010
1328E89E-7EC8-4F7E-809E-7E945796E511
SharePoint Server 2010 Standard Trial
B2C0B444-3914-4ACB-A0B8-7CF50A8F7AA0
SharePoint Server 2010 Standard
3FDFBCC8-B3E4-4482-91FA-122C6432805C
SharePoint Server 2010 Enterprise Trial
88BED06D-8C6B-4E62-AB01-546D6005FE97
SharePoint Server 2010 Enterprise
D5595F62-449B-4061-B0B2-0CBAD410BB51
Search Server 2010 Trial
BC4C1C97-9013-4033-A0DD-9DC9E6D6C887
Search Server 2010
08460AA2-A176-442C-BDCA-26928704D80B
Project Server 2010 Trial
84902853-59F6-4B20-BC7C-DE4F419FEFAD
Project Server 2010
ED21638F-97FF-4A65-AD9B-6889B93065E2
Office Web Companions 2010
926E4E17-087B-47D1-8BD7-91A394BC6196