Tuesday, May 29, 2012

Designing large lists and maximizing list performance (SharePoint Server 2010)

This is MSDN article, which is very useful for all the developers who are dealing with the large CMS.

This article provides information about the performance of large document libraries and large lists. The recommendations in this article are the result of a series of performance tests that were conducted with Microsoft SharePoint Server 2010. The focus of this article is on the performance characteristics of large lists and on how different configurations affect the performance of large lists and of the farm. SharePoint Server 2010 has several new improvements that make it easier to create and use large lists. However, creating and implementing large lists still requires careful planning. You must consider many factors, such as information architecture, performance, disaster recovery, and governance. This article covers information architecture and features that are used to implement large lists, and it covers the effect that specific configurations have on performance.

further details at MSDN.

Values chosen in the Document’s Information Panel (DIP) not being saved in the SharePoint library for Managed Metadata columns

We set up a document library with a content type. We got 14 custom columns (6 managed metadata, 2 Person or Group, 5 Text & 1 Date types).  Property promotion/demotion is enabled (SPWeb.ParserEnabled -> true)

When users save a new document into the library they are prompted (DIP) to choose values for these columns.

We are seeing problems related to values chosen in the document’s information panel (DIP) not being saved in the SharePoint library after the document is saved.
The values seem to be saved with the document, when I reopen it from library the values again show in the DIP. So it seems like there is a problem with SharePoint actually reading the document metadata from the Office file even though the metadata is stored in the file.

A related problem arises when I upload a document, set metadata values through the document property form in SharePoint (not in the DIP), then edit the document in Office where I change the metadata values in the DIP, and then resave document back into the SharePoint library. Then the library displays the original metadata values even though they are changed in the Office file itself.

Workaround,
Still following up with MS for the resolution and cause behind broken sync functionality, but workaround to this problem is Add new Managed Metadata Column to the same document library. Test functionality or problem of saving managed metadata. ( it stated working for us). Now delete newly added Managed Metadata column.

Please leave your comments.

Wednesday, May 23, 2012

Jquery and Javascript date calculation /Weekdays calculation.

Jquery and Javascript date calculation /Weekdays calculation.
Open sharepoint page in edit mode.
Add content editor webpart to page at the end.
Add below script to content editor webpart.

// JScript source code
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js">script>
<script src='/_layouts/SP.js' type='text/javascript'>script>
<script type=""text/javascript"">
    var myItems;
    var countHolidays = 0;
 
    $("input[name='CONTROL_NAME$DateTimeField$DateTimeFieldDate']").focusout(function () {
 
        var dtfrom = $("input[name='CONTROL_NAME$DateTimeField$DateTimeFieldDate']").val();
 
        var dtto = $("input[name='CONTROL_NAME$DateTimeField$DateTimeFieldDate']").val();
 
        if (dtfrom.length > 0 && dtto.length > 0) {
            var DaysDiff;
            var bussDays = calcBusinessDays(new Date(dtfrom), new Date(dtto));
            GetHolidays(dtfrom, dtto);
 
            DaysDiff = bussDays - countHolidays;
 
            $("#ctlCONTROL_ID_TextField").val(DaysDiff);
        }
 
    });
 
    function calcBusinessDays(dDate1, dDate2) { // input given as Date objects
        var iWeeks, iDateDiff, iAdjust = 0;
        if (dDate2 < dDate1) return -1; // error code if dates transposed
        var iWeekday1 = dDate1.getDay(); // day of week
        var iWeekday2 = dDate2.getDay();
        iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1; // change Sunday from 0 to 7
        iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;
        if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1; // adjustment if both days on weekend
        iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1; // only count weekdays
        iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;
 
        iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000);
 
        if (iWeekday1 <= iWeekday2) {
            iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1);
        } else {
            iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2);
        }
 
        iDateDiff -= iAdjust; // take into account both days on weekend
 
        return (iDateDiff + 1); // add 1 because dates are inclusive
    }
 
 
    // this function will find date difference in days.
    function daydiff(first, second) {
        var start = new Date(first);
        var end = new Date(second);
        var diff = new Date(end - start);
        return (diff) / (1000 * 60 * 60 * 24)
    }
 
 
    function GetHolidays(fromdate, todate) {
        var myQueryString = '' + todate + '' + fromdate + '';
 
        var myContext = new SP.ClientContext.get_current();
        var myWeb = myContext.get_web();
        var myList = myWeb.get_lists().getByTitle('Holidays');
        var myQuery = new SP.CamlQuery();
        myQuery.set_viewXml(myQueryString);
        myItems = myList.getItems(myQuery);
        myContext.load(myItems, 'Include(ID, Title, Date, Year)');
        myContext.executeQueryAsync(Function.createDelegate(
                                this, GetHolidaysSuccess),
                     Function.createDelegate(
                                this, GetHolidaysFail));
    }
 
    function GetHolidaysFail(sender, args) {
        //alert('GetEmployeesByAge() failed:' + args.get_message());
        //return false;
    }
 
    function GetHolidaysSuccess(sender, args) {
        var HolidaysCount = myItems.get_count();
 
        var currYear = (new Date).getFullYear();
 
        var holidaysEnumerator = myItems.getEnumerator();
        var holidaysDetails = '';
 
 
 
        // Loop through all items
        while (holidaysEnumerator.moveNext()) {
            // Get current item
            var currentHoliday = holidaysEnumerator.get_current();
            if (currentHoliday.get_item("Year") == currYear) {
                countHolidays = countHolidays + 1;
            }
        }
    }
script> 

How to change the font of the Richtextbox of sharepoint library/list when it gets focus/ cursor on it.

How to change the font of the Richtextbox of sharepoint library/list when it gets focus/ cursor on it.

Open New Item page in edit mode.

Add content editor webpart to page at the end.

Add below script to content editor webpart. (Make sure that you change your control id in below code).

<script type="text/javascript" src="http://code.jquery.com/jquery.min.js">script>
<script type="text/javascript">
    $("div#ctl00CONTROL_NAME").focus(function () {
        alert("in");
        var e = jQuery.Event("keydown");
        e.which = 13;
        $("input[name='FontSizeStyleValue']").val("25pt").trigger(e);
        alert("End");
    });
    alert("Thanks for visiting!");
script>

Saturday, May 19, 2012

Javascript: The column name that you entered is already in use or reserved. Choose another name.

When you’re creating columns either the Site Columns or the List Columns in SharePoint, it might show a message stating

“The column name that you entered is already in use or reserved. Choose another name.”.

Ideally, If it is reserved column name then you should avoid giving that name.

Still there are cases when you have to change the name.....

Here is the fix for this issue.

Just check all the columns in the list.Any column with the same name(both display name and internal name)? - No. Then that must be reserved name.

FIX :

There is a javascript array variable which had all collection of forbidden column names. Clear this array and then try creating the column.

To clear the columns the following script should be entered in the address bar of the browser and hit enter.

javascript:g_FieldName={};alert('Successfully cleared column Names');

The above script clears all the values in the forbidden column collection array and gives you a confirmation. Now try creating the column now.You should be able to.