Fwd: Hard Work Redefined


Some of the great words from the real motivator Manish Gupta from Chrysalis….just wanted to spread the word to larger audience. Some people think smart work is a substitute for hard work…
Regards,
Sudhir Kesharwani
sudhir.kesharwani@gmail.com
———- Forwarded message ———-
From: MG's Desk! <desk.mg@chrysalis.net.in>
Date: Sat, May 15, 2010 at 5:56 PM
Subject: Hard Work Redefined

Dear Chrysalian,

Working Hard is considered as one of the most important pathways to achieving success. Since centuries sages, masters, wise men, elders, consultants have been advocating, endorsing and supporting the above statement. I too am in alignment with these folks. (Should I miss out on an opportunity of being linked to the wise ones? ) 

New age generation wants to stick on to Smart Work but I believe even Smart Work involves some “Work”.( and many a time ends up with lots of Hard Work) There is no substitute for Hard work. 

I want you to read the above statement one more time and focus on the fact of Hard work leading to success, which implies that if our understanding of Hard work is not what it should be then chances are high that we may not be anywhere near our desired goal. Lets understand Hard work from a different perspective. Lets understand the difference between hard Work and working hard for success.

When in office an executive works as per his schedule and finishes what he had planned to do , this is called hard work, but when the same executive over and above his daily tough schedule goes for an evening course for technical up gradation – this is called working hard for success . At home when a home maker after a tough morning grind of the daily chores takes out time to learn sitar which she so dearly wanted since childhood- that’s called working hard for success. A father on coming home tired and exhausted after a long days haul plays with his children with the same vibrancy and freshness which he had at the start of a new day, then it is called working hard for success. A cycle rickshaw puller works real hard for more than 12 hours a day, but he’ll be working hard for success when you spot him talking to a co-operative bank for the loan of his second rickshaw. An Entrepreneur when working hard to set his business in motion also thinks and acts on succession planning then it is said he’s working hard for success. ( I wonder how Dhirubhai Ambani missed out on that one) 

The concept of working hard for success is the same whether you are a student, a businessman, a sports person or a spouse. Other than our regular work (where we have really worked hard) what are we doing extra to maximise our output is called working hard for success.

Its almost midnight and I feel I have been working hard for success for the day..

Love you lots and wish you a “Hard Working” Life …

MG

jQuery – Announcement carousel for SharePoint


The Annoucements Carousel
Your web part should look like following image (announcements.jpg). You will see all the announcements scrolling one by one, Announcement items are linked to the actual announcement page. When you hover the mouse pointer over a news item, the scrolling will stop automatically.

Note: All the required files can be downloaded from GitHub – jQuery SharedCode is pasted in the email body for reference.
Overview
Recently I have been working on jQuery Carousel plug in and SharePoint. Accidently/fortunately I was able to develop an announcement carousel solution. I thought of posting this to the broader audience. I find this really useful as we can show all the announcements in the smaller area.
Prerequisites
Make sure you have an announcements list in your SharePoint site with some sample announcements.
Step 1 – Required JavaScript and CSS file.
Following files are required for this carousel functionality.
-          jQuery library – jQuery 1.4.1 library,  you can download it from the jQuery site.  I love to rename it to jQuery-latest.min.js.  I have used jQuery-1.4.2.min.js
-          jCarousel script –I have updated the original jCarousel script for hoverPause functionality as per the comments given in the plug in page.  Make sure to use the same.
-          News-Ticker-Source.js – this file contains the actual source code to query the announcements links and making it carousel. Make sure to replace {Site Url} with your site url.
-          News-ticker.css – Contains style sheet for the announcements list.
The folder structure that I followed in my site is as following, highlighted the folders in the hierarchy.
-          Shared Documents
o   BIN
§  JQLIB – this folder contains all the JavaScript files
·         jQuery-latest.js
·         jcarousellite_1.0.1.hoverPause.js
·         news-ticker-source.js
§  CSS -  this folder contains folder for the style sheet and required images
·         News-ticker : Folder for the style sheet.
o   Images: folder for images
§  News1.jpg
§  Mic1.jpg
o   News-ticker.css : CSS filefor styling.
Note: I have given this folder structure since my code has all the references based on this folder structure, however you can have your own folder structure; make sure to update the references in the HTML script and news-ticker-source.js files.
Step 2 – The JavaScript Code
All the required files are attached with this email. Still thought of putting the code of news-ticker-source.js on to this post.
$(document).ready(function()
{
                //Call the method to read data from annoucements list and display it as carousel.
                GetAnnoucementData();
});
/*
This function reads the data from annoucement list and passes the control to processResults method
This makes and ajax call to lists.asmx web service.
Make sure to replace {Site URL} with your SharePoint site url.
*/
function GetAnnoucementData()
{
//Prepare the SOAP envelop for calling GetListItems method from lists.asmx web service
var soapEnv = “<soapenv:Envelope xmlns:soapenv=’http://schemas.xmlsoap.org/soap/envelope/’> \
   <soapenv:Body> \
    <GetListItems xmlns=’http://schemas.microsoft.com/sharepoint/soap/’> \
     <listName>Announcements</listName> \
     <viewFields> \
      <ViewFields> \
                                 <FieldRef Name=’ows_ID’ /> \
                                 <FieldRef Name=’LinkTitleNoMenu’ /> \
                                 <FieldRef Name=’Body’ /> \
                                 <FieldRef Name=’Expires’ /> \
                                 <FieldRef Name=’Author’ /> \
      </ViewFields> \
     </viewFields> \
    </GetListItems> \
   </soapenv:Body> \
  </soapenv:Envelope>”;
/*Post the request envelop to web service thorugh ajax request and pass the results to processResults method*/                                      
        $.ajax({
            url: “{SITE URL}/_vti_bin/lists.asmx”,
            type: “POST”,
            dataType: “xml”,
            data: soapEnv,
            complete: processResult,
            contentType: “text/xml; charset=\”utf-8\”"
        });   
}
/* This method parses the resultant xml and prepares the display.
Please replace {Site Url} with your sharepont site url.
*/
function processResult(xData, status)
{
                                //Select the root element.
        var newnews =$(“#newsItems”);
        var rows;
                               
                                //Check if query returns no rows
        if (xData.responseXML.getElementsByTagName(“z:row”).length==0)
        {
                                                //Prepare the display for 0 rows.
                                                var url = “{SITE URL}/Lists/Announcements/”;
                                                var head = “<li><div class=’thumbnail’> <img src=’{SITE URL}/Shared%20Documents/BIN/css/news-ticker/images/news1.jpg’></div>”;
            var body = “<div class=’info’>No news items<a href=” + url + “> Read all</a> <span class=’cat’> no items found</span></div>”;
                                                var tail = “<div class=’clear’></div></li>”;
                                                var liHtml = head + body + tail;
                                               
                                                //Append the HTML element to newNews element
            newnews.append(liHtml);
        }
        else
        {
                                                //Read all the rows from responseXml
                                                rows = xData.responseXML.getElementsByTagName(“z:row”);
                                                jQuery(rows).each(function()
                                                {
                                                //Read the information from returned rows
            var url = “{SITE URL}/Lists/Announcements/DispForm.aspx?ID=” + $(this).attr(“ows_ID”);
                                                var title = $(this).attr(“Title”);
                                                var news = $(this).attr(“ows_Body”);
                                                var author = $(this).attr(“ows_Author”);
                                                author = author.split(‘#’)[1];
                                                //Prepare the div element
                                                var head = “<li><div class=’thumbnail’><img src=’{SITE URL}/Shared%20Documents/BIN/css/news-ticker/images/news1.jpg’></div>”;
            var body = “<div class=’info’><a href=” + url + “>” +  $(this).attr(“ows_Title”)+ “</a> <span class=’cat’>by ” + author + “</span></div>”;
                                                var tail = “<div class=’clear’></div></li>”;
                                                var liHtml = head + body + tail;
                                                //Append the resultant element onto newNews element
            newnews.append(liHtml);
                                                });
        }
                               
                                //Append entire newNews element to root Div
                                newnews.appendTo(“.newsticker-jcarousellite”);
                               
                                //Prepare the Carousel of all the returned items
                                $(“.newsticker-jcarousellite”).jCarouselLite({
                                vertical: true,
                                hoverPause: true,
                                visible: 4,
                                auto:500,
                                speed:1000
                                });
    }
Step 3 – The HTML Script
Add a content editor web part on your home page and add following HTML Script in the source editor. (Make sure to update the references of script and css files, replace {SITE URL} with your site url).
<link rel=”stylesheet” href=”{SITE URL}/Shared%20Documents/BIN/css/news-ticker/news-ticker.css” type=”text/css” media=”screen” />
<script src=”{SITE URL}/Shared%20Documents/BIN/jqlib/jquery-latest.min.js” type=”text/javascript”></script>
<script src=”{SITE URL}/Shared%20Documents/BIN/jqlib/jcarousellite_1.0.1.hoverPause.js” type=”text/javascript”></script>
<script src =”{SITE URL}/Shared%20Documents/BIN/jqlib/news-ticker-source.js” type=”text/javascript”></script>
<div id=”newsticker-demo”>   
     <div class=”newsticker-jcarousellite”>
                                <ul id=”newsItems”>
        </ul>
    </div>
</div>
<div id=’status’></div>
References
-          http://sorgalla.com/jcarousel/
Regards, Sudhir Kesharwani MCTS – MOSS 2007 | MCTS – WSS 3.0 | MCPD-EA | MCSD.NET 

Creating default Security Groups for new site collection


Everyday in SharePoint makes you learn something new…this is very true

Al though it is a very small issue and most of us might be knowing this but still thought of sharing with community. In my current assignment we are provisioning SharePoint sites using Workflows and Workflow activities.

I have a list that is used to record a request for new site collection,  i have also developed a custom Visual Studio workflow that contains one custom workflow activity to create a new site collection. My list contains a field that accepts Site Template based on which the new site collection gets created.

Till now everything looks good, but when i create a site based on Team Site through code my new site collection looked different then when it is created using central admin.

It just had one security group where as when we create site using same site template using central admin we can see three groups

1. Site Members

2. Site Owners

3. Site Viewers

After googling around i came to know that apart from provisioning site, SharePoint central admin makes some method calls to provision default security group.

SPSite.CreateDefaultAssociatedGroup(string PrimaryOwnerLogin, string SecondaryOwnerLogin, string GropuPrefix)

This method call will make default security groups (Members, Owners, Visitors) for your new site collection with all the required permissions. 

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.createdefaultassociatedgroups.aspx

This method is called automatically by SharePoint central admin.

Regards,

Sudhir Kesharwani

Notes field is displayed as multi text box


There is one thing about SharePoint that is very fascinating and frustrating.  No matter how much expertise you have gained or since how long you are working with SharePoint.  It always defeats you and makes you feel that there is still a lot to learn.

Today i learnt some thing really tiny and good thing about SharePoint notes field.

We had a requirement wherein we wanted to keep the record of activities that a user is performing against a list item.

We created a site column of type “Note” with “AppendOnly” set to “TRUE”.  I added it to the required content type and then to list schema in order to provision the list with a field named “Activity Notes”.

Till now everything looks good, but guess what,  when i deployed the solution and provisioned a list,  the Notes field was displayed as normal “Multi Line text box”,  on top of that it was behaving the same way and user was able to delete everything.

Where as i expected it to behave like a “Append Only” text box that shows the history of comments, (the way the Comments field behave in issue list).

Accidently i got to know that in order to “notes” field work with “append only” it is mendatory that “Versioning” is enabled in the list.

I updated the list schema to have “VersioningEnabled” set to “TRUE” and everything started working as expected.

Happy Learning….

Sudhir Kesharwani

Getting Workflow Association from Content Type of Sharepoint Lists


Recently i have been working on Sharepoint Custom Workflows and Workflow Association with Sharepoint Lists and Content Type within the list. Thought of sharing some of the learnings from my experience.

Once the workflow is associated with Content Type/SPLists, its very common to update Workflow Instances.
As the workflow assembly keep on changing, Whenever you deploy new version of Workflow Assembly/Workflows Solution Package, SharePoint updates the workflow association to restrict new instance of the workflow. Even if the workflow class is not modified.
To over come this we need to get the workflow association object from List/Content type, depending on how we have associated the workflow.
If you want to update workflow association to allow new instances, you need to get a reference of Workflow Association Object and Enable it.
1. Getting Workflow Association Object from Content T(when workflow is associated with content type of Sharepoint List)

private SPWorkflowAssociation GetAnnualApprovalWFAssociation(SPContentType contentType)
{
SPWorkflowAssociation resultWFAssociation= null;
//Loop through all the workflow associations and return the correct one
foreach (SPWorkflowAssociation wfAssociation in contentType.WorkflowAssociations)
{
if(wfAssociation.BaseId == Constants.workflowGuid)
resultWFAssociation= wfAssociation;
}
return resultWFAssociation;
}
}
Note: SPWorkflowAssociations collection class defines two methods that can be used to get the workflow associations

  • GetAssociationByBaseID(wfGUID)
  • GetAssociationByName(name,cultureInfo)

This methods will return value only when the WorkflowAssociations are not restricted to allow new instances. Hence you can not completely trust this methods. This is why i have used a work around which loops through all the workflow associations (including deactive one) and compare the workflow association with Workflow GUID.

2. Getting workflow association with Sharepiont List

> SPList object contains a collection called WorkflowAssociations which is same as content type’s workflow association object, so you can replace SPContentType object with SPList object and the above method will work.

Enabling WorkflowAssociation to AllowNewInstance

Once you have reference of SPWorfklowAssociation object, you can just set it’s enabled property to true and invoke UpdateWorkflowAssociation(SPWorkflowAssociation) method on Content Type or SPLIst object.

SPWorkflowAssociation wfAssociation = GetWorkflowAssociation(myList);

wfAssociation.Enabled = true

myList.UpdateWorkflowAssociation(wfAssociation);

This action will enable the workflow association.

This is perticularly very useful when you have lots of sites already created in your environment that are using the Workflow, and you re-deploy the workflow assembly. So instead of doing it through sharepoint workflow settings page, you can write a tool that leverages the Sharepoint Object Model and updates the workflow associations for all your existing sites.

Iterating through Sharepoint Discussion List Replies


Hi,

Recently i had been working extensively in the integration of sharepoint discussion list and the document library.

I had one requirement where i have to iterate through the replies of a sharepoint discussion thread, i could hardly find any posts related to that.

First of all Sharepoint discussion lists are very different then other sharepoint lists. It is very different becase it stores the data differently. If you look at the settings of discussion list you will find that it contains two content types

1. Discussion Content Type

2. Messages Content Type

If you digg further you will find that discussion content type is derived from sharepoint folder content type and messages content type is derived from item content type.

Each message(reply) in the discussion list contains a field called ParentFolderId. This field is hidden from the new/edit/view forms of discussion list.

This field always contains id of the root folder for this message (e.g. id of the root discussion thread)

so if you want to get a reference of root discussion thread(aka folder), you can use following piece of code(considering that you have reference to the message)

int rootDiscussionThreadId = ListItem["ParentFolderId"].ToString();

So when you start a new discussion, internally sharepiont creates a folder withthe subject of the discussion, moving forward all the replies to the root discussion thread are nothign but items created inside the root discussion thread.

Discussion List

> Discussion – 1

–>Message 1

–>Message 2

> Discussion – 2

–>Message 1
–>Message 2

> Disccusion – 3

–>Message 1
–>Message 2

So if you iterate through all the items in the sharepoint list using he normal SPList.Items property, you will get reference of all the root folders (not the replies.)

Even when you navigate to flatView.aspx for any discussion thread, or any other page related to discussion thread you will always find a query string parameter named rootFolder, this query string parameter holds the unique id of the discussion folder.

Getting Replies of a Discussion

If you are in a situation where you have to loop through replies of a perticular discussion thread, you can use folowing code (assuming that you have obtained parent folder / reference of discussion item)

SPQuery queryText = new SPQuery();
queryText.Query = <>;
queryText.Folder = discussion.Folder;
//IMP: setting the folder will get items from that perticular folder
SPListItemCollection relatedDiscussions = discussion.ParentList.GetItems(queryText);

Please note that since we want to query items from a perticular folder of the discussion list, we are setting the folder property of SPQuery object to the folder that we want to query. Since my discussion is nothign but a folder in the discussion list, i am setting the folder using that discussion object.

When this query is executed, relatedDiscussion collection will contain list of replies for the given discussion folder,

Pune User Group Meet – First Public Appearance


Saturday13th Dec 2008 was a superb day of my life,

I had taken my first session on Windows Sharepoint Services 3.0 with one of my best collegue Akhilesh Nirapure (akhilesh.nirapure@gmail.com).

It was my first public appearance on the Sharepoint. Giving me motivation for futher session.

I see that WSS 3.0/MOSS 2007 is still a jargon for most ot the people. The crowd was a good mix of people, starting with young studends (member of microsoft student partner) till IT Head of the company who were the decision makers.

It was a wonderful experience, I hope that it is the same for the audience. Apparently i had gone for Pune User Group meet for the first time (that too as a speaker).

Checking if logged in user is member of Sharepoint Site


To check if current logged in user is member of current site. We could loop through groups available for the current site and check if user is member of the group.

SPWeb object defines a method SPWeb.IsCurrentUserMemberOfGroup(int groupid). This method takes the credentials of logged in user and Group ID as parameter.
Group id can be obtained from SPGroup object. SPWeb object also has one property SPWeb.Groups. Simply loop through this collection and check if logged in user is member of this group.

Following code snippet checks if user is member of group (except visitor group).

SPWeb web = SPContext.Current.Web;
bool isMember = false;
foreach (SPGroup group in web.Groups)
{
//If it is visitors group, do not check user membership
if(group != web.AssociatedVisitorGroup)
isMember = web.IsCurrentUserMemberOfGroup(group.ID);
//Check if user is member of this site.
if (isMember==true)
break;
}
if (isMember)
{
// other task to do if user is member
}

Note:
SPWeb class has properties that can be used to determine Visitors Groups/Members Groups and Groups associated with web site.

AssociatedGroups
Gets a list of the groups that are associated with the Web site.
AssociatedMemberGroup
Gets the users who have been given contribute permissions to the Web site.
AssociatedOwnerGroup
Gets or sets the associated owner groups of the Web site.
AssociatedVisitorGroup
Gets or sets the associated visitor group of the Web site.

Happy MOSS…ing!!!
Sudhir Kesharwani

Passed 70-542 – MOSS Application Development


hi,
I completed my sharepoint certification series by passing the other Application Development certification paper 70-542 MOSS 2007 Application Develpoment.
It was relatively much easier then the previous paper (70-541 – WSS 3.0 Application Development).
I had done all the preperation from just one book, “Inside Microsoft Office Sharepoint Server 2007″ by
by Patrick Tisseghem, this book contains everything you need to get your MCTS credentials for MOSS- Application Development.

Most of the questions were from following topics, i think you should go through following chapters really carefully before going for exam:
Chapter3- Customizing and Extending the Microsoft Office Sharepoint 2007 Search

Chapter4 – Working With Business Data Catelog.

Chapter7 – Integrating with Excel Services.

Chapter8 – Policy and Records management.

Belive me this paper is much more easier then Windows Sharepiont Services paper, and contains most of the questions from sharepiont settings and out of the box functionaliy.

All the best…

Passed 70-541 – WSS Application Development


Hi,

I cleared 70-541 WSS Application Development, 70% of the questions were from APIs..

Here are some of the areas that i remember :

Features:
- A lot of questions were asked from this area, feature deployment, attaching event handlers with features
- There was a question which asked how we can get a list of features activated in a farm.

Workflows:
- Question on how to associate custom pages with workflows.
- Creating and updating a task using workflows.
- deploying workflows and associating it with document library.
- Deploying workflows and assiciating it with content types.

Admin APIs
- Questions related to changing settings using code.

Alerts & SPJobDefination
- Browsing through user alerts,
- changing frequency of user alerts.
- There was a question in which we have to get user alerts for 1 week using CAML query.
- There was another question where we need to fetch all the alerts that were to be sent on every monday for 5 weeks ( 5 occurances).
- Browsing through all the active job definitions.

Masterpages and Layouts
- Setting masterpages of all the rootsite and subsites using API.

WebParts
- Creating webparts and deploying.
- Deploying webparts as feature and hosting user control.
- Creating connectable webparts and passing data between webparts.

SiteDefinition and SiteTemplates
- Creating site definitions, there were lot of scripts given.
- Specifying a configuration that will be applied to only rootweb.
- Creating site templates that is based on the default site definition.