Showing newest posts with label SharePoint Basics. Show older posts
Showing newest posts with label SharePoint Basics. Show older posts

Wednesday, February 10, 2010

Enhancement / Addition in WSS 3.0 compared to WSS 2.0

Hi all,

Although a topic which is so old I guess, however many times people generally ask about the difference or should say new enhancements and additions in WSS 3.0 versions as compared to WSS 2.0.So in this article, I thought of sharing with you most important changes in WSS 3.0 compared to WSS 2.0.

Item security – Now you can set item level permissions in document library or list. You can also set the permissions on folder level as well.

RSS support – you can now view all updates of list or library by using RSS.

Tree View support – You can now view tree view of your site’s content and sub site and its content.

Survey – You can now have additional conditional branching and page breaks.

People and Group type – You can now use people and group field type to select any people or group.

Master Page – now the look and feel is controlled by master page.

Send to link – You can now send a link of document or send document to other locations.

Email receives – Libraries can now receive emails.New site templates – You can now use wikis and blogs site templates as well.

Link security – To show up a link, user at least should have read permission.

Gantt chart support – You can now create Gantt chart for any type of list based on start date and stop date.


Undelete – Now you can recover deleted list and library items.


Enhanced bread crumb – you can see the last visited page before the current one at the top of the page.


Workflow enhancements – Now any list or library can have one or more workflow associated with it.

Hope this is useful information, specially for interview. :)

Read More…

Thursday, January 7, 2010

How to embed video in SharePoint

Hi All,

Sometimes we require adding video content to our SharePoint site. There is a very simple way to achieve this functionality.

All we need is Content editor web part to be placed on the page. Source of video file can be from same web application or it can be external source as well or video sitting on some shared drive of your network which everybody has an access.

Go ahead and add content editor web part.

Add following line of code.

<Embed
src="{URL of video / Shared Path pointing to video file}"
width=350
height=350
align=center
autostart=false
loop=false
quality=high
allowFullScreen=true>
</Embed>

See the output below.



And that’s it. You are good to play your video file.
Read More…

Wednesday, December 16, 2009

Limiting the number of responses in survey

Hi All,

In this article, I am going to share one very important aspect of survey. Many times we require limiting number of responses from survey. However SharePoint does not provide us with the facility to limit the number of responses.

Ok, then how to achieve this? Here we go, follow these simple steps and you are good to go.

(1) Write one web part and write one code which checks for the total responses for specific survey. Add this web part on NewForm.aspx and overview.aspx, all responses and graphical summary of the survey. You get NewForm.aspx when you click on respond to the survey button.

(2) Write down simple code, check URL, if NewForm word exist, then just count the total number of item in survey and if it exceeds let’s say 30 responses, and then redirect back to Source parameter.

(3) If in URL overview, allitems or summary exist, just count the total number of item in survey and if it exceeds let’s say 30 responses then write a statement saying you are not allowed to respond because it has already reached to the maximum responses.

Your job is done.
Read More…

Friday, December 4, 2009

Add Choice column to list programmatically

Hi All,

Some days back person asked me as a question that you have a post for how to add data in the choice column programmatically however you do not have any article on how to add choice column itself to the list programmatically.

So of course, taking the suggestion positively here is a way you can add choice column programmatically to the list or document library.

Considering lstCustomList is your list object and you have set AllowUnsafeUpdate() to true for the web object. We are adding two choices in the choice column.

First we will add choice column itself to the list and then we will add the choices in that column and update the field. The main point to taken in to consideration is that it is SPFieldChoice not the SPField.

lstCustomList.Fields.Add("ABC", SPFieldType.Choice, false);
lstCustomList.Update();
SPFieldChoice objChoiceCol = (SPFieldChoice)lstCustomList.Fields["ABC"];
string[] strdata = new string[2];
strdata[0] = "Open";
strdata[1] = "Close";
objChoiceCol.Choices.Add(strdata[0]);
objChoiceCol.Choices.Add(strdata[1]);
objChoiceCol.Update();
lstCustomList.Update();


That is it. Your job is done.
Read More…

Sunday, September 6, 2009

Creating and working with Survey in SharePoint - Part 5

Hi All,

In this article we will discuss about how to hide the save button. You may wonder why we should hide the save button. We will hide the save button to avoid one big issue of the survey.

If you have not gone through the survey articles, I would recommend you to read them all first before you read further.

Creating and working with Survey in SharePoint - Part 1

Creating and working with Survey in SharePoint - Part 2

Creating and working with Survey in SharePoint - Part 3

Creating and working with Survey in SharePoint - Part 4

When you have any question that has branching, SharePoint automatically places the next question on the second page and gives you an option to save your response so that later you can edit it. If you have the long survey that has many branching questions, then SharePoint does this splitting of page between the questions. Here we have one big problem. When responder saves the response, you will see that number of response increases. If you have five responders and all five of them have saved the respond, not completed the respond, then first thing you will notice is you can see total number of responses as five, but when you will actually go to the survey and find out then you won’t see even a single response. So where are all those responses?

Well, answer to this question is really simple. Even though you have full rights on survey or even you are a site administrator or site collection administrator, nobody can see those responses except a person who has saved the response. Only he can see his saved response. So bottom line is check columns named “Completed” in “All Responses” view, you will find only those responses whose status is yes. If a person has saved response, he will see status as “no” in “Completed” column.

Now why we are talking about hiding the save button is because there can be a reason where in you want responders to respond the survey in specific days. If they don’t then you want to send mail to them one more time to indicate that look, you need to fill this. Now to know this that how many people have not responded to survey yet, is don’t allow to save the response so that you can have exact number of responses.

Ok, so let us go ahead and add the content editor web part in every page of your questions, so that save button doesn’t appear on each and every page of survey. So now responder has no choice but to fill in the survey at one go.

In content editor web part, place the following code.

<script language="JavaScript">
var ClassName;
ClassName = 'ms-toolbar';

var elements = new Array();

var elements = document.getElementsByTagName('td');

for(var e=0;e<elements.length;e++)
{
if(elements[e].className == ClassName)
{

elements[e].innerHTML = elements[e].innerHTML.replace('value=Save','value=Save style=visibility:hidden ');



}

}

</script>


Your job is done. Now see the effect of above code.



That's it.
Read More…

Saturday, September 5, 2009

Creating and working with Survey in SharePoint - Part 4

Hi All,

Here I am going to discuss something interesting especially on overview.aspx of survey list. If you have not gone through the survey articles, I would recommend you to read them all first before you read further.

Creating and working with Survey in SharePoint - Part 1

Creating and working with Survey in SharePoint - Part 2

Creating and working with Survey in SharePoint - Part 3

and

Creating and working with Survey in SharePoint - Part 5


One question came in my mind. Why any responder of survey should care about knowing when survey was created and how many number of responses has come so far. If we have set the permission in advance settings of survey that user can only see their response, and then also responder can see how many responses have come so far.

If we do not want to allow any responder to see when survey was created and how many responses has come so far, then do one very easy thing. Just add one more content editor web part on the overview.aspx page of survey and copy and paste the below code and there you go, you have each and every option just like you have in normal survey web part on overview.aspx. The only difference is that here you cannot see number of responses and date created. Make sure that you hide the default web part on that page by modifying that web part and setting hidden to true under layout option. So simple…isn’t it.

Just make sure that you replace the {siteurl} for HREF in below code. Just place your site url there and you should be good to go.


<table class="ms-menutoolbar" cellpadding="2" cellspacing="0" border="0" id="ctl00_m_g_c84f415c_dba8_4240_b34d_263e596c7eed_ctl00_ctl00_toolBarTbl" width="100%" >
<tr> <td class="ms-toolbar" nowrap="true">
<div class="ms-buttoninactivehover" onmouseover="this.className='ms-buttonactivehover'" onmouseout="this.className='ms-buttoninactivehover'"><a id="ctl00_m_g_c84f415c_dba8_4240_b34d_263e596c7eed_ctl00_ctl00_toolBarTbl_RptControls_ctl00_diidIONewItem" accesskey="N" title="Respond to this Survey" onclick="javascript:NewItem('\u002fsites\u002fTest\u002fLists\u002fSharePoint\u002520site\u002520survey\u002fNewForm.aspx');return false;" href="javascript:__doPostBack('ctl00$m$g_c84f415c_dba8_4240_b34d_263e596c7eed$ctl00$ctl00$toolBarTbl$RptControls$ctl00$diidIONewItem','');"><img align='absmiddle' alt="Respond to this Survey" src="/_layouts/images/NewItem.gif" style='border-width:0px;'>&nbsp;Respond to this Survey</a></div>
</td>
<td class=ms-separator><img src='/_layouts/images/blank.gif' alt=''></td>
<td class="ms-toolbar" nowrap="true">


<span style="display:none"><menu type='ServerMenu' id="zz13_RptControls" largeIconMode="true"><ie:menuitem id="zz14_ExportToSpreadsheet" type="option" iconSrc="/_layouts/images/MenuSpreadsheet.gif" onMenuClick="javascript:EnsureSSImporter();javaScript:ExportList('\u002fsites\u002fTest\u002f_vti_bin\u002fowssvr.dll?CS=65001\u0026Using=_layouts\u002fquery.iqy\u0026List=\u00257BA1B0E302\u00252D497E\u00252D45B9\u00252D9994\u00252D9F0E0171A380\u00257D\u0026View=\u00257BC84F415C\u00252DDBA8\u00252D4240\u00252DB34D\u00252D263E596C7EED\u00257D\u0026RootFolder=\u00252Fsites\u00252FTest\u00252FLists\u00252FSharePoint\u002520site\u002520survey\u0026CacheControl=1')" text="Export to Spreadsheet" description="Analyze items with a spreadsheet application." menuGroupId="800"></ie:menuitem><ie:menuitem id="ctl00_m_g_c84f415c_dba8_4240_b34d_263e596c7eed_ctl00_ctl00_toolBarTbl_RptControls_ctl01_ctl00_ctl03" type="separator"></ie:menuitem><ie:menuitem id="zz15_ViewRSS" type="option" iconSrc="/_layouts/images/MenuRSS.gif" onMenuClick="window.location = '/sites/Test/_layouts/listfeed.aspx?List=%7BA1B0E302%2D497E%2D45B9%2D9994%2D9F0E0171A380%7D';" text="View RSS Feed" description="Syndicate items with an RSS reader." menuGroupId="800"></ie:menuitem><ie:menuitem id="zz16_SubscribeButton" type="option" iconSrc="/_layouts/images/MenuAlert.gif" onMenuClick="window.location = '/sites/Test/_layouts/SubNew.aspx?List=%7BA1B0E302%2D497E%2D45B9%2D9994%2D9F0E0171A380%7D&amp;Source=http%3A%2F%2Fsharepointkings%3A7777%2Fsites%2FTest%2FLists%2FSharePoint%2520site%2520survey%2Foverview%2Easpx';" text="Alert Me" description="Receive e-mail notifications when items change." menuGroupId="800"></ie:menuitem></menu></span><span title="Open Menu"><div id="zz17_ListActionsMenu_t" class="ms-menubuttoninactivehover" onmouseover="MMU_PopMenuIfShowing(this);MMU_EcbTableMouseOverOut(this, true)" hoverActive="ms-menubuttonactivehover" hoverInactive="ms-menubuttoninactivehover" onclick=" MMU_Open(byid('zz13_RptControls'), MMU_GetMenuFromClientId('zz17_ListActionsMenu'),event,false, null, 0);" foa="MMU_GetMenuFromClientId('zz17_ListActionsMenu')" oncontextmenu="this.click(); return false;" nowrap="nowrap"><a id="zz17_ListActionsMenu" accesskey="C" href="#" onclick="javascript:return false;" style="cursor:hand;white-space:nowrap;" onfocus="MMU_EcbLinkOnFocusBlur(byid('zz13_RptControls'), this, true);" onkeydown="MMU_EcbLinkOnKeyDown(byid('zz13_RptControls'), MMU_GetMenuFromClientId('zz17_ListActionsMenu'), event);" onclick=" MMU_Open(byid('zz13_RptControls'), MMU_GetMenuFromClientId('zz17_ListActionsMenu'),event,false, null, 0);" oncontextmenu="this.click(); return false;" menuTokenValues="MENUCLIENTID=zz17_ListActionsMenu,TEMPLATECLIENTID=zz13_RptControls" serverclientid="zz17_ListActionsMenu">Actions<img src="/_layouts/images/blank.gif" border="0" alt="Use SHIFT+ENTER to open the menu (new window)."/></a><img align="absbottom" src="/_layouts/images/menudark.gif" alt="" /></div></span>
</td>
<td class=ms-separator><img src='/_layouts/images/blank.gif' alt=''></td>
<td class="ms-toolbar" nowrap="true">


<span style="display:none"><menu type='ServerMenu' id="zz18_RptControls" largeIconMode="true"><ie:menuitem id="zz19_AddQuestions" type="option" onMenuClick="window.location = '/sites/Test/_layouts/qstNew.aspx?List=%7BA1B0E302%2D497E%2D45B9%2D9994%2D9F0E0171A380%7D&amp;Source=http%3A%2F%2Fsharepointkings%3A7777%2Fsites%2FTest%2FLists%2FSharePoint%2520site%2520survey%2Foverview%2Easpx';" text="Add Questions" description="Add an additional question to this survey." menuGroupId="100"></ie:menuitem><ie:menuitem id="zz20_ListSettings" type="option" iconSrc="/_layouts/images/MenuListSettings.gif" onMenuClick="window.location = '/sites/Test/_layouts/survedit.aspx?List=%7BA1B0E302%2D497E%2D45B9%2D9994%2D9F0E0171A380%7D';" text="Survey Settings" description="Manage questions and settings for this survey." menuGroupId="200"></ie:menuitem></menu></span><span title="Open Menu"><div id="zz21_ListSettingsMenu_t" class="ms-menubuttoninactivehover" onmouseover="MMU_PopMenuIfShowing(this);MMU_EcbTableMouseOverOut(this, true)" hoverActive="ms-menubuttonactivehover" hoverInactive="ms-menubuttoninactivehover" onclick=" MMU_Open(byid('zz18_RptControls'), MMU_GetMenuFromClientId('zz21_ListSettingsMenu'),event,false, null, 0);" foa="MMU_GetMenuFromClientId('zz21_ListSettingsMenu')" oncontextmenu="this.click(); return false;" nowrap="nowrap"><a id="zz21_ListSettingsMenu" accesskey="I" href="#" onclick="javascript:return false;" style="cursor:hand;white-space:nowrap;" onfocus="MMU_EcbLinkOnFocusBlur(byid('zz18_RptControls'), this, true);" onkeydown="MMU_EcbLinkOnKeyDown(byid('zz18_RptControls'), MMU_GetMenuFromClientId('zz21_ListSettingsMenu'), event);" onclick=" MMU_Open(byid('zz18_RptControls'), MMU_GetMenuFromClientId('zz21_ListSettingsMenu'),event,false, null, 0);" oncontextmenu="this.click(); return false;" menuTokenValues="MENUCLIENTID=zz21_ListSettingsMenu,TEMPLATECLIENTID=zz18_RptControls" serverclientid="zz21_ListSettingsMenu">Settings<img src="/_layouts/images/blank.gif" border="0" alt="Use SHIFT+ENTER to open the menu (new window)."/></a><img align="absbottom" src="/_layouts/images/menudark.gif" alt="" /></div></span>
</td>

<td width="99%" class="ms-toolbar" nowrap><IMG SRC="/_layouts/images/blank.gif" width=1 height=18 alt=""></td>


<td class="ms-toolbar" nowrap="true">

<table border=0 cellpadding=0 cellspacing=0 style='margin-right: 4px'>
<tr>
<td nowrap class="ms-toolbar" id="topPagingCellWPQ2">
<td>
</tr>
</table>

</td>
<td class=ms-separator> </td>
<td class="ms-toolbar" nowrap="true">

<table border=0 cellpadding=0 cellspacing=0 style='margin-right: 4px'>
<tr>
<td nowrap class="ms-listheaderlabel">View:&nbsp;</td>
<td id="ctl00_m_g_c84f415c_dba8_4240_b34d_263e596c7eed_ctl00_ctl00_toolBarTbl_RightRptControls_ctl01_ctl00_onetViewSelector" nowrap="nowrap" class="ms-viewselector" onmouseover="this.className='ms-viewselectorhover'" onmouseout="this.className='ms-viewselector'">
<span style="display:none"><menu type='ServerMenu' id="zz22_ViewSelectorMenu" CompactMode="true"><ie:menuitem id="zz23_DefaultView" type="option" onMenuClick="window.location = '/sites/Test/Lists/SharePoint site survey/overview.aspx';" text="Overview" menuGroupId="100"></ie:menuitem><ie:menuitem id="zz24_View1" type="option" onMenuClick="window.location = '/sites/Test/Lists/SharePoint site survey/AllItems.aspx';" text="All Responses" menuGroupId="300"></ie:menuitem><ie:menuitem id="zz25_View2" type="option" onMenuClick="window.location = '/sites/Test/Lists/SharePoint site survey/summary.aspx';" text="Graphical Summary" menuGroupId="300"></ie:menuitem></menu></span><span title="Open Menu"><div id="zz26_ViewSelectorMenu_t" class="ms-viewselector" onmouseover="MMU_PopMenuIfShowing(this);MMU_EcbTableMouseOverOut(this, true)" hoverActive="ms-viewselectorhover" hoverInactive="ms-viewselector" onclick=" MMU_Open(byid('zz22_ViewSelectorMenu'), MMU_GetMenuFromClientId('zz26_ViewSelectorMenu'),event,true, 'ctl00_m_g_c84f415c_dba8_4240_b34d_263e596c7eed_ctl00_ctl00_toolBarTbl_RightRptControls_ctl01_ctl00_onetViewSelector', 0);" foa="MMU_GetMenuFromClientId('zz26_ViewSelectorMenu')" oncontextmenu="this.click(); return false;" nowrap="nowrap"><a id="zz26_ViewSelectorMenu" accesskey="W" href="#" onclick="javascript:return false;" style="cursor:hand;white-space:nowrap;" onfocus="MMU_EcbLinkOnFocusBlur(byid('zz22_ViewSelectorMenu'), this, true);" onkeydown="MMU_EcbLinkOnKeyDown(byid('zz22_ViewSelectorMenu'), MMU_GetMenuFromClientId('zz26_ViewSelectorMenu'), event);" onclick=" MMU_Open(byid('zz22_ViewSelectorMenu'), MMU_GetMenuFromClientId('zz26_ViewSelectorMenu'),event,true, 'ctl00_m_g_c84f415c_dba8_4240_b34d_263e596c7eed_ctl00_ctl00_toolBarTbl_RightRptControls_ctl01_ctl00_onetViewSelector', 0);" oncontextmenu="this.click(); return false;" menuTokenValues="MENUCLIENTID=zz26_ViewSelectorMenu,TEMPLATECLIENTID=zz22_ViewSelectorMenu" serverclientid="zz26_ViewSelectorMenu">Overview<img src="/_layouts/images/blank.gif" border="0" alt="Use SHIFT+ENTER to open the menu (new window)."/></a><img align="absbottom" src="/_layouts/images/blank.gif" alt="" /></div></span>
</td>

</tr>
</table>

</td>

</tr>
</table>


<TABLE class="ms-summarystandardbody" cellpadding=0 cellspacing=0 width=600px style="margin: 10px;" border=0 rules=rows> <TR> <TD class="ms-formlabel" width=190px ID="overview01">Survey Name:</TD> <TD class="ms-formbody" >Movie knowledge survey</TD> </TR> <TR> <TD class="ms-formlabel" valign="top" ID="overview02">Survey Description:</TD> <TD class="ms-formbody">This is the startbold Hindi endbold as well as the startitalic English movie enditalic Knowledge survey. linebreak

we would like to know how much people are startunderline aware about the Hindi and English movies endunderline</TD> </TR> <TR> <TD><IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></TD> </TR> </TABLE>
<TABLE border=0 style="margin: 0px 8px 0px 8px;">
<tr><td><img src="/_layouts/images/blank.gif" width=1 height=4 alt=""></td></tr>
<tr>
<td nowrap>
<img src="/_layouts/images/rect.gif" alt=""><span class=ms-toolbar>&nbsp;</span>
<a class="ms-toolbar" ACCESSKEY=R ID=diidSurveyResults HREF="{siteurl}/Lists/SharePoint site survey/summary.aspx"><!-- _locID_text="overview05" _locComment="{StringCategory=TXT}"-->Show a graphical summary of responses</a>
<span class=ms-toolbar>&nbsp;</span>
</td>
</tr>
<tr>
<td nowrap>
<img src="/_layouts/images/rect.gif" alt=""><span class=ms-toolbar>&nbsp;</span>
<a class="ms-toolbar" ACCESSKEY=U ID=diidResultsByUser HREF="{siteurl}Lists/SharePoint site survey/AllItems.aspx"><!-- _locID_text="overview06" _locComment="{StringCategory=TXT}"-->Show all responses</a>
<span class=ms-toolbar>&nbsp;</span>
</td>
</tr>
</TABLE>


And see the effect of the above code.




That's it.
Read More…

Creating and working with Survey in SharePoint - Part 3

Hi All,

We are going to discuss more on survey in this article. If you have not gone through the previous articles, I would suggest you to go through those articles first and then proceed for reading.

If you haven't gone through the previous articles of this series, i would highly recommend to read following articles before proceeding.

Creating and working with Survey in SharePoint - Part 1

Creating and working with Survey in SharePoint - Part 2

and

Creating and working with Survey in SharePoint - Part 4

Creating and working with Survey in SharePoint - Part 5

Now, that we have survey list already created and if you see the description of the survey on the overview.aspx, there is a difference in the survey description in the webpart and survey description below survey name. Check this out.



The difference is the line break. If you observe, survey description in the web part is written as it is without any line break however survey description under the name of survey breaks two separates sentences into two different lines because when we created the survey we gave it like that.

So in this article we will discuss two important things that will help you not only for the survey but also for any other list and any other document library as well.

Here we will remove the survey description below the name of the survey because we can already see the description in the web part and also we will include the HTML in the description now. It is very much similar to what we have learnt in previous articles just a class name change and that will do our job. Let us see in detail.

Ok, Edit the overview page and place the content editor web part below to the original web part.



Ok, first let us go and change the description of survey. Go to settings, survey settings, title and description and change the description to the following.

This is the startbold Hindi endbold as well as the startitalic English movie enditalic Knowledge survey. linebreak


we would like to know how much people are startunderline aware about the Hindi and English movies endunderline.

Ok, now go back to the overview view of the survey and observe the survey description.



As you can see those words start appearing in the description, so we need to get rid of it and replace them with the actual HTML behavior and that is what we did in previous articles. So go ahead and modify the content editor web part and place the following code in that. Note one important line in the below code and that line is where we assign “ms-formbody’ class. Earlier we assigned “ms-formlabel” in previous articles to add HTML in questions.

<script language="JavaScript">
var ClassName;
ClassName = 'ms-formbody';

var elements = new Array();

var elements = document.getElementsByTagName('td');

for(var e=0;e<elements.length;e++)
{
if(elements[e].className == ClassName)
{
elements[e].innerHTML = elements[e].innerHTML.replace('linebreak','<br/>');

elements[e].innerHTML = elements[e].innerHTML.replace('startunderline','<u>');

elements[e].innerHTML = elements[e].innerHTML.replace('endunderline','</u>');

elements[e].innerHTML = elements[e].innerHTML.replace('startitalic','<i>');

elements[e].innerHTML = elements[e].innerHTML.replace('enditalic','</i>');

elements[e].innerHTML = elements[e].innerHTML.replace('startbold','<b>');

elements[e].innerHTML = elements[e].innerHTML.replace('endbold','</b>');

}

}

</script>



And there you go, see the effect of it.



Ok, look good now. But there is a problem here, still look at the survey description above the web part. It still shows the words (startbold, endbold etc). They have not been replaced yet.

How to replace them? Ok, here is the answer. Just add one more content editor web part below the previous content editor web part and copy the same HTML content above, just make two changes. Change the class name and getElemtByID from TD to Div as this description is in the div tag, not in the TD tag.

ClassName = 'ms-listdescription'
var elements = document.getElementsByTagName('div');


and there you go, see the magic.



Actually for this specific survey type of list, we don’t need this to be here as on the same page, we can see the survey description in the web part. So let us go and remove the description of survey below the name of the survey from overview.aspx.

Modify the last content editor web part and paste the following code inside it.

<script language="JavaScript">
var ClassName;
ClassName = 'ms-listdescription';

var elements = new Array();

var elements = document.getElementsByTagName('div');

for(var e=0;e<elements.length;e++)
{
if(elements[e].className == ClassName)
{

elements[e].innerHTML = '';
}

}

</script>


And see the effect of above code. Survey description is gone.



Remember one very important point. You need to place this last content editor web part in every view page. We placed it only in overview.aspx. Just try and change the view to “All responses” and “Graphical summary”. Survey description will appear there, so just make sure that you place the last content editor web part on each view page separately as well.
Read More…

Sunday, August 30, 2009

Creating and working with Survey in SharePoint - Part 2

Hi All,

Here I am back with some more interesting stuff in survey list. In previous post we discussed about the advantages of survey list. But it is not true in every case. It has got many other limitations as well. Here in this article, we are going to discuss about one basic difficulty about survey.

I would first suggest you to read Creating and working with Survey in SharePoint - Part 1 of the series.

For further reading read Creating and working with Survey in SharePoint - Part 3

Creating and working with Survey in SharePoint - Part 4

Creating and working with Survey in SharePoint - Part 5

If you want to have some HTML in survey’s question, then we cannot insert that. Sometimes we may require making some font bold, something italic and we want to underline something. We need to increase the font size, we may require to add hyperlink in question, then we cannot do it.

So anyways we have to overcome this problem anyhow. So here is a way how you can insert HTML in the question of survey.

First make a note of one very important point, you have to repeat these steps for each and every page that you have for the survey. Means if you have branching question then you get more than one page to respond.

Before getting actually in to this, you first need to understand that how we will replace the normal text with HTML text.

Ok, let us go back to our first question. Open the question and add the following words before and after Department.



See the effect of this change on questions. We can clearly read startitalic and enditalic in first question.



We have added these words and we will replace this word with startitalic with <i> and enditalic </i> in content editor web part. You can use whatever word that you want, we only need to replace those words in the web apart. Let us see how we will do this now.

Go ahead and add one content editor web part below the questions. Edit the page and add the content editor web part.

Click on modify shared web part, click on source editor and write the code as shown in below.

<script language="JavaScript">
var ClassName;
ClassName = 'ms-formlabel';

var elements = new Array();

var elements = document.getElementsByTagName('td');

for(var e=0;e<elements.length;e++)
{
if(elements[e].className == ClassName)
{

elements[e].innerHTML = elements[e].innerHTML.replace('startitalic','<i>');

elements[e].innerHTML = elements[e].innerHTML.replace('enditalic','</i>');


}

}

</script>



Let us have a look on this above code. Here what we have done is that we have first taken out ms-formlable class as questions belong to this class in SharePoint architecture. We then take all ID because all questions are in TD tag and then we find our forcefully entered two words and replace them with proper HTML tag and there you go. See the effect of the above code.



Let us go ahead and change our third question. Make the following change in it.



Now again go ahead and change the existing editor web part with following addition with above code.

elements[e].innerHTML = elements[e].innerHTML.replace('linebreak','<br/>');

elements[e].innerHTML = elements[e].innerHTML.replace('startunderline','<u>');

elements[e].innerHTML = elements[e].innerHTML.replace('endunderline','</u>');


The effect of the above code is shown below. We have also broken question in two lines.



Now let us go and create hyperlink in the same question. Here is a trick to add hyperlink to the question. Let us say for example we want to have a hyperlink on “like” word and that should take to the Home page link and it should open in new page. In addition to this, it should be of bigger size than other words.

So here is a simple answer of the tuff question. Add just one more line to your content editor web part.

elements[e].innerHTML = elements[e].innerHTML.replace('like','<a href="/sites/Test/default.aspx" target="_blank" style ="font-size:14pt" >like</a>');


and see the effect of above code.



I hope that now you have the clear picture. All it takes is the knowledge of HTML and you can insert anything, almost anything with HTML in the questions.

I will soon come up with part 3. keep reading it.
Read More…

Creating and working with Survey in SharePoint -Part 1

Hi All,

Today we will learn about SharePoint Survey list. A very useful and very interesting list with many advantage and bit of limitations as well. First let us understand the advantage.

Whenever you want to collect the responses from various people, across your organization about any event, any activity or any other thing, Survey is best suited list. It allows you to collect the responses in various ways. You can ask the questions and they can answer those questions and then result can be analyzed by taking it to the excel sheet or through graphical summary or by watching all responses at once.

You can have as many questions as you want and the format of their answers can also be of great varieties. For example, you may want to ask one question whose answer is simple text or multiple line of text with formatting. You can also have a question whose answer is choice (selection in terms of radio buttons, check boxes, drop downs). You can have question whose answer can be a date. We can have all these with built in survey list.

Another advantage of survey is that you can also add branching logic in it. That means, let us say, you have one question which depends upon the answer of some other question. To show or not to show a question depends upon the answer of previous question. This kind of branching can also be done in survey list.

So all and all at very basic level, if we would like to collect responses from people, survey is the best choice.

Let’s see the basic steps involved in the creating Survey List. Go to Create and select the Survey under tracking category. Give the name and description like shown below. Observe that you have one setting which says allow multi responses. If you want to collect multiple responses from individual person, then you should allow this else don’t allow this. This basically allows responder to respond to survey more than one time.



So we are going to create movie quiz. Once you are done with the creation of the survey list, we now need to add questions to add and have to decide what kind of answer each question has.

I know many people may not like this survey as it seems funny. But my main intension is to let you know how we can create it and what are the options available for answers and how branching can be done.

So go ahead and add the questions to it. Click on settings -> Add Question and add the first question. Click next question after creating each question.

1) Your Department -> Single line of text
2) Your Location -> Single line of text
3) What kind of movies do you like? -> Multiple lines of text and plain text.

Ok, now we are going to give user a choice. Either he can go for Hindi quiz or he can go for English quiz.

So go ahead and create one question, again by selecting settings->Add Question.

4) Which movie quiz would you like to give? -> Choice, Type: Radio button and add Hindi and English in the text box provided.

Now we actually want to branch the user directly to the questions of Hindi cinema and English Cinema depending on user’s choice. We cannot branch the question right now. That can be done after adding all questions and that will be done from the survey settings page. So now we will move ahead and add the Hindi cinema questions.

Go ahead and add question.

5) Rate yourself in Hindi Cinema.>Rating scale. Here we can define the sub questions and each question can have rating scales. So add following questions to it.
a. Old year movies (1950-1970)
b. Medium year movies (1971-2000)
c. Latest movies (2000-2009)


6) Add next question. Name the actor whose famous dialogue is “Kitne Aadmi the?” Choice, drop down and add following options. Jay, Gabbar, Veeru

7) Add next question. Name the upcoming movie of Akshay Kumar which is said to be captured under water. Single line of text.

8) Add next question. Rate yourself in English Movies.>Rating scale. Here we can define the sub questions and each question can have rating scales. So add following questions to it.
a. Old year movies (1950-1970)
b. Medium year movies (1971-2000)
c. Latest movies (2000-2009)


9) Add next question. Name the actor who was gifted God power in the movie "Bruce Almighty'. Single line of text.

10) Add next question. What was the version number mention in the latest movie of “Die Hard" series? Choice and options are 3.0, 4.0, and 3.5.

11) Last we will ask about the suggestion. Add question “Any suggestions that you want to give…” Multi lines of text.

If you want to have page break and then want to ask next question in next page, then add page separator and then add the next question so that this question will come on next page and not one the same page.

After adding these questions, your settings page should look something like this



Now, open the main page of survey list. It should look like below image and it shows description of the survey, number of responses when it was created and click to see all responses and show a graphical summary.



Ok, now go to survey settings and see that Branching logic column is empty as we have yet not defined any branching. We want to branch the question as per the question in which we asked that what movie quiz you would like to give. If user selects Hindi, then we want to jump to the Hindi questions without asking for English movie questions and if user selects English, we need to jump to the English movie questions without asking for Hindi movie questions.

So go ahead and click the question which asks for the selection of movie quiz and select like shown below. This defines that when user clicks on Hindi he will be redirected to the first Hindi question else he will be redirected to English question.



Add one more branching with the question which asks about Akshay Kumar’s upcoming movie and add branching logic as shown below. We need to add this branch because if user selects Hindi, then all questions of English movie will also come and we don’t want that so we will branch to the last question from this Akshay Kumar’s question so that no English questions asked. Here what we have done is whatever the response is, we will jump to the last question.



Now go back and click on respond to this survey. You will see that it asks only up to the question whose answer branches the next question.



Fill the details, select Hindi and click next, then as you can see you are presented with a screen where you get the Hindi movie questions and one interesting thing is save button in between. That means if you have very long survey and it has many branching logic, then you can save the survey and then continue at your own convenience at any time.



Click next and finally fills up the final text box and there you go, you are done with responding your first survey. If you observe the column Completed, you will find “yes” because we have completed the survey. If you would have saved it in between somewhere, you would have find it “No”, that means it is partially saved. You get “Yes” only when somebody fills the entire survey.

I will discuss bit deep about this in my coming articles of survey series. If you now click on respond to survey, you will get an error saying that you cannot give response for more than one time. If you have saved your survey, then you can click on the survey and complete that survey again.

One very important thing to note here is that person who creates the survey has to make sure that whether to allow user to see only his response or he can see everybody’s response. Same goes for editing options, should he allows to change other’s response or his own only. These settings are very important, if these options are set, then even user clicks on View all responses, he will be able to see only his response. Same is true in the case of graphical summary. He cannot see other responses from other people.

This is basically called Item level security. To set this on survey, go to Settings->Survey settings->advanced settings. Here you will find an option to set these properties. There you can also set to allow these responses to be a part of SharePoint search.

You can also export the result into excel as the option is available in the action menu.

Read Creating and working with Survey in SharePoint -Part-2

and

Creating and working with Survey in SharePoint - Part 3

Creating and working with Survey in SharePoint - Part 4

Creating and working with Survey in SharePoint - Part 5

for further interesting reading.
Read More…

Saturday, August 15, 2009

Changing sequence and adding new menu items in SharePoint

Hi All,

As I have explained you in my previous post about the menu items in the toolbar on AllItems.aspx page. We will take the same code and sample here and I will explain you today how to play with the Menu items inside the menus.

So this post is all about changing the sequence of menu items and adding new menu items.

First let me show you how you can change the position of individual items in the menu. Considering we are playing with Actions menu and we want to change the “View RSS Feed” to appear with the Edit in Datasheet option.

Ok, let me clarify one thing very clearly. We should not change the default place of menu items as they are actually categorized properly and they have been placed in respective group items. For example, it doesn’t make sense if you place Alert Me option with Edit in Datasheet option. Does it make sense to have this option with Datasheet option? Answer is absolutely no.

But this is just for fun purpose and also to give you an idea about how to do that. Before we actually go in to the code, I would like to share here that each of these menu options fall under MenuGroupID.

First observe the below figure closely. See Red circle, Bur circle and green circle.



Now see the below image of menu items



See, There is only one red circle because see the first category. We have only one single item here which is EditInDatasheet. See two blue circles, we have two items in the menu category (Export to Spreadsheet and Open with Access) and last we have again two circles shown in green color represents last two options. (View RSS Feed and Alert Me). As you can see all belongs to MenuGroupId. First item has id number 200; second two items have id number 400 and last two items have id number 500.

So now we will play the trick and we will move View RSS Feed with EditinDatasheet. All we need to do is just change the MenuGroupId of RSS Feed from 500 to 200 so that it will come with ExportinDatasheet.

foreach (Control childControl in ParentControl.Controls)
{

if (childControl.ToString().ToUpper() == "Microsoft.SharePoint.WebControls.ActionsMenu".ToUpper())
{

ActionsMenu Menu = (ActionsMenu)childControl;
Menu.Visible = true;

if (Menu.GetMenuItem("ViewRSS") != null)
{
Menu.GetMenuItem("ViewRSS").MenuGroupId = 200;
}

break;
}
CheckControl(childControl);
}


See the effect of this code,



If we want View RSS Feed to appear first and Datashet option to come second, then just a little modification will do this for us. We only need to add one single line only.

if (Menu.GetMenuItem("ViewRSS") != null)
{
Menu.GetMenuItem("ViewRSS").MenuGroupId = 200;
Menu.GetMenuItem("ViewRSS").Sequence = 0;
}




This is the way you can change the menu item from one place to the other place.

Now how about adding a menu item template to Menu? Let us go ahead and add menu item template to the Actions menu.

MenuItemTemplate objTemplate = Menu.AddMenuItem("MailMeID", "Mail Me From Hotmail",
"/_layouts/images/SPSPROFL.GIF",
"This will take you to hotmail", "", strClientURL);

objTemplate.MenuGroupId = 200;





Once you click on this item, it will take you to hotmail.com. Ok, now how about adding a client side code to it? As you can see in my previous code, I kept the last parameter blank. That is where we need to right the client event.

Just to demonstrate you, I have used the built in Client Click of RSS feed and assigned it to our new menu item.


if (childControl.ToString().ToUpper() == "Microsoft.SharePoint.WebControls.ActionsMenu".ToUpper())
{
ActionsMenu Menu = (ActionsMenu)childControl;
Menu.Visible = true;
string strClientURL = "window.location = '/sites/Test/_layouts/listfeed.aspx?List=%7BA6B5F63B%2DB860%2D418F%2DBEB0%2D8DAFC72C1C6B%7D';";
MenuItemTemplate objTemplate = Menu.AddMenuItem("MailMeID", "Mail Me From Hotmail",
"/_layouts/images/SPSPROFL.GIF",
"This will take you to hotmail", "", strClientURL);


objTemplate.MenuGroupId = 200;

break;
}


You can change this url to your desired page in the site. Once you click on Mail me from Hotmail, it will take you to RSS Feed page.



If you add one more single line of code which is shown below, we get that new menu item with separator. It separates it with the other menu items with one line. Note that we have commented the MenuGroupID assignment, so that it becomes a separate group.

if (childControl.ToString().ToUpper() == "Microsoft.SharePoint.WebControls.ActionsMenu".ToUpper())
{

ActionsMenu Menu = (ActionsMenu)childControl;
Menu.Visible = true;

string strClientURL = "window.location = '/sites/Test/_layouts/listfeed.aspx?List=%7BA6B5F63B%2DB860%2D418F%2DBEB0%2D8DAFC72C1C6B%7D';";

MenuItemTemplate objTemplate = Menu.AddMenuItem("MailMeID", "Mail Me From Hotmail",
"/_layouts/images/SPSPROFL.GIF",
"This will take you to hotmail", "", strClientURL);

Menu.AddMenuItemSeparator();

//objTemplate.MenuGroupId = 200;

break;
}




Ok, now once again let us get the DesigntimeHTML and see what the new things that we have got,



Check out the new menu item added. I have highlighted it with blue underline and also see the new MenuGroupID that we got. It is 2147483647. So now we know that if any other menu item we want to add with the same group, we need to assign this number to the new MenuItemtemplate as we saw in the beginning of this post.

I am finding more interesting about this, I will be eager to share it with you all-time supportive readers.
Read More…

Sunday, August 2, 2009

Working with KPI List – Part 1

Hi All,

We all know about the importance of goal in business. Business works on set goals, so it is very important to track where they are, matching the goal, ahead of goal or behind the goal. To answer this question, SharePoint has come up with feature called KPI (Key Performance Indicator).

Key Performance Indicator as name suggests, it gives an idea about where we are performing related to goal. They are found in Report center site, so if you are in WSS working environment, do not think of using this feature because you are not going to get this. This is moss feature.

So let’s get started and understand how it works.

KPI is a special type of list, so while creating a list; we need to select this special list as KPI list, not a normal custom list. When you create a KPI list, then click new, you will see the difference. This is the difference.

Here is a sample of creating KPI list and how the data is entered in it. So first we will create a normal list which will hold the data that will be used in KPI list. Create a list as shown below.



Now observe here that we have sales goal against January of each year. Keep this thing as of now in your mind.

Let us go back to KPI list, Create KPI list and name it as you like.

Once you are done with creation, just click on new and observe the change, here you can see four options.



As you can see, first options says you can create KPI using list options, second option says that you can create KPI using excel workbook, third says that you can create KPI using Sql server 2005 analysis services and the last options says that you can create KPI using manual entry.

We are going to see three out of these four. We will not cover analysis service KPI. We will cover rest of it.

So let us get started and try to create KPI from List option. So click on the first option, once you click on it, it will take you to a page where you can enter the List url from which we want to fetch the data, select the list that we created earlier and click on number of list items in view. Scroll below and enter 8 and 6 respectively like shown below.



Let me explain you what all settings we just did. We have counted the number of items in the list. If total number of items in the list meets criteria of 8 or above, KPI gives green symbol. If total number of items in the list is 6 or 7 then it gives us yellow triangle. If total number of items is below 6 than it gives red square symbol.

So let us go back and see how many items we have in list, we have five items entered in it.



Now let’s go ahead and add more two rows in the list.



Now go back to KPI list and refresh the page and see symbol changes to the yellow triangle that meets to our criteria.



Now go back and add one more item to it to complete our goal of 8 items in the list and that will turn our KPI symbol to green circle.



That completed our simple example of generating KPI based on total number of items in the list. If you have observed while creating KPI, you must have seen other two options as well. It says that you can also go for the percentage value. Other is calculating average, calculating sum etc kind of a function. We will go for calculating average sales. So let’s add one more KPI which is again from List data. So click on new and select KPI from list option. In the page, shown name the KPI and then select third radio button. Select your list by specifying URL and selecting view as All items, here you can also mentioned your specific view for which you want to generate KPI, so this gives us more flexibility for criteria based KPI as well. After this select column as “Sales Goal” and select average from the drop down. Provide 1000 in the goal and 600 in warning textbox. You should have something which looks similar to shown below.



We have specified that if the average sale is 1000 or more, we are safe and it shows green symbol. If it’s between 600 to 999, we are in a warning stage else we are in danger zone and indicated by red square.

Here we have this entry in our base list.



Because average sales is higher than we specified (which is $1,000 in our case), KPI indicator shows us green symbol.



To know more on the same KPI, just click on the KPI item that we have just created; it will take you to a page which shows more detailed information.



Now, go ahead and change the sales values accordingly. When you change the value which makes the average change in them, when average goes below 999 it will start showing yellow triangle and if average changes below 600, it will start showing red square.

Ok, now let us start analyzing the other options which is entering manual information KPI, it is very simple process of giving static data. You just need to give a value and select the criteria goal for it and it simple displays the image depending on the value that you have entered like shown below.

You can also create a KPI indicator which will come from the excel file. But before starting on this, you need to create SSP for this, because the excel file that we are going to use here must be under the trusted location. So create the SSP from central administration and click on the excel trusted file location. Give the entire path till your library name in which your excel book resides. Once you are done with this, then only you will be able to use this feature. So go ahead and create one more KPI indicator and this time select the indicator using data in excel work book. Once you click on this, you need to give the URL of the workbook. So go ahead and select your work book. Now here, once you select the workbook, you need to give the cell number here to mention your indicator value. Along with this you also need to give the cell number for goal and cell number for warning.

This is the snapshot of excel workbook that I have created. In this workbook, in Shhet1 I have mentioned Sales data.



Here D11 cell is an average of sales goal value of D4 to D8 which is our target value as indicator. H$ value indicates the goal to achieve and H7 is the warning sales goal. So let’s specify these values in respective field as shown below.



Just see at the indicator field in KPI list,

Let’s prepare one workbook which look like this, here D11 is calculated column which is average of all sales figures. Cell H4 represents the goal to be achieved and cell H6 represents the warning match.

So here we will specify our criteria like shown above in workbook figure.

Go ahead and have a look at the KPI list how it looks like.



Try to open the workbook for editing and see the changes in the indicator values, you will see different indicators shown in the KPI list.

Now, we are almost done with our examples of KPI. Just one more topic left to discuss which a KPI web part is. We are done with creating KPI list, its supporting list but there is one more thing, which is web part that supports the KPI list. So let’s go ahead and add web parts. Click on edit page, where you want to put this web part. This web part will basically pulls the KPI data from the KPI list and shows details at one go.

Find web part which is named “Key Performance indicators” under Dashboard category. Once you add it, click on modify shared web part and select the KPI list.



One more web part is there which says KPI Details under same Dashboard category. So go ahead and add that web part on the page, click on modify shared web part. Select KPI list, here you will find all KPIs that you have mentioned in the KPI list in the drop down. From there you can select KPI. In this example, I have selected the excel sales data calculation KPI and selected icon as checkmark and result is shown below.



That is it. i will soon come with part 2.
Read More…

Sunday, July 12, 2009

Working with Recycle Bin in SharePoint

Hi All,

Many times we require working with the Recycle bin of the web site in SharePoint. Here in this article I am going to discuss something interesting classes and their methods and properties for achieving this functionality in SharePoint.

First to start with, when we want to gain an access on recycle bin object at site or individual web level, then call RecycleBin property of SPWeb or SPSite object. This will give you SPRecycleBinItemCollection object.

Each item in SPRecycleBinItemCollection is SPRecycleBinItem. Let me explain you certain properties offered by SPRecycleBinItem object.

(1) Author – Gets the User who created the item.
(2) AuthorEmail - Gets the Email of the user who created this item.
(3) AuthorName – Gets the display name of the User who created this item.
(4) DeletedBy – Gets the User who deleted the item.
(5) DeletedByEMail – Gets the Email of user who deleted the item.
(6) DeletedByName – Gets the name of the use who deleted the item.
(7) DirName – Gets the relative URL of the list or folder which originally captained the item.
(8) ItemType – Gets type of an item deleted, what type of an item it was. It returns the SPRecycleBinItemType and it is enumeration which has following values.

Attachment : Specifies an attachment.
File :Specifies a file.
FileVersion: Specifies a file version.
Folder: Specifies a folder.
FolderWithLists: Specifies a folder that contains a list.
List :Specifies a list.
ListItem: Specifies a list item.

Remember one important thing. When you have child sites under your site collection, then when you delete any item it goes in to your web's recycle bin. When you delete an item from that recycle bin, it goes in to the site collection's recycle bin. so you can also get your deleted item from there.

These were certain properties of the class. Now I would like to highlight certain methods of the class.

(1) Delete: the item permanently from the recycle bin.
(2) MoveToSecondStage – this method moves the item from individual web’s recycle bin to the Site Collection recycle bin.
(3) Restore – As a name suggests, it restores the item to the original location.


Let us look into one more aspects of working with Recycle bin. We normally use SPQuery or SPSiteDataQuery to work with the queries from list and document library. But here to work with the Recycle bin, we will use SPRecycleBinQuery class.

SPRecycleBinQuery objQuery = new SPRecycleBinQuery();
objQuery.RowLimit = 100;
objQuery.OrderBy = SPRecycleBinOrderBy.Default;
SPRecycleBinItemCollection recycleitems = objWeb.GetRecycleBinItems(objQuery);


Now we have got the recycleitems, so you can iterate through them and can access properties and also work with methods.

That’s it.
Read More…

Sunday, July 5, 2009

Features and Solutions with WSS Object model

Hi All,

Today I am going to discuss about the features and solutions. I know you will ask me what is new in this. Well, this time we are going to talk about features and solutions in terms of object model.

We are going to discuss following things.

(1) Feature install and uninstall
(2) Feature activation and deactivation
(3) Solution install and uninstall
(4) Feature properties

We will discuss all in terms of object model. So let us start one by one. First we will take feature install and uninstall.

Now when we create feature and place it in to 12 hive folder and when we run the -o installfeature command, we actually installs the feature at farm level and when we run –o uninstallfeature command, we actually uninstalls the feature at farm level. Now how this can be done programmatically. So here is a way.

But before starting on this, we also need to learn one more object which is SPFarm class. To initiate SPFarm class, we need to know the configuration database connection path, just like ordinary connection path to connect to the database we use in ADO.NET.

For example, this can be a connection string for my configuration database.

string strConnectionString = @”server=localhost\myServer;initial catalog=SharePoint_Config_75980120-a9bf-4p71-3401-qn26385ca059;IntegratedSecurity=SSPI;”;

SPFarm objFarm = SPFarm.Open(strConnectionString);
SPFeatureDefinitionCollection objinstalledFeatures = objFarm.FeatureDefinitions;
objinstalledFeatures.Add(“{new feature}”, new Guid(“guid of feature “));


This will install the new feature at farm level. Now let’s see how to uninstall the feature from farm level.

objinstalledFeatures.Remove(new Guid(“guid of feature “));

Ok, this was about installing the feature at farm level; now let’s talk about activating feature at site level.

Considering objWeb refers to a site, then

objWeb.Features.Add(new Guid({guid of feature}));


And same to deactivate the feature from site level,

objWeb.Features.Remove(new Guid({guid of feature}));


Now let us understand what we mean by feature properties. Each feature has set of properties that you can set along with it and also built in properties that you can enumerate and check. We will insert properties in the feature.

This is how you enumerate to the properties of the feature.

foreach (SPFeatureProperty objProperty in objFeature.Properties)
{
String strPropName = objProperty.Name;
String strPropValue = objProperty.Value;
}


Now let us see how we can add and remove the properties from feature.

SPFeatureProperty objProp = new SPFeatureProperty(“{your prop name}”, “{prop value}”);
objFeature.Properties.Add(objProp);


SPFeatureProperty objProp = objFeature.Properties[0];
objFeature.Properties.Remove(objProp);


Interesting thing to note is that you do not need to call any update method on any of the objects to achieve this behavior.

Now let us take solution in to picture. By solution we mean collectively we can install features at farm level (on every server in the farm) and deploy features to those servers.

We know that every operation that I have mentioned in this article can be achieved through STSADM command, so this operation can also be performed by –o addsolution and –o deletesolution command. But here we are talking about object model, so I will show you the way to do it programmatically.

Consider the objFarm object just like mentioned above and then if you access the Solutions property, it will give you all solutions deployed at farm level.

It can be done simple as add and remove method.

objFarm.Solutions.Add({customapp.cab});
objFarm.Solutions.Remove(new Guid({guid of solution})); // Pass Guid of solution


You can enumerate through all solutions in Farm, like mentioned below.

foreach (SPSolution objSolution in objFarm.Solutions)
{
//your custom code
}


Each objSolution has different properties like Deployed, DeployedServers, Id, Name etc.

Again each DeplyoedServer represents SPServer class and has properties like Name. So in a nutshell, you can make use of these classes and play with it.

At the end I would like to summarize with what we discussed in the article with classes.

SPFeature – Represents individual feature
SPFeatureCollection – Represents collection of features at site level
SPFeatureDefinition – Represents Feature definition.
SPFeatureDefinitionCollection – Represents all feature definitions of farm
SPFeatureProperty – Individual property of feature
SPFeaturePropertyCollection – All properties of single feature
SPFarm – represents Farm
SPSolution – Represents solution file.
SPServer – Represents each server on which solution is deployed in Farm.

Thank you.
Read More…

Sunday, June 28, 2009

Getting all documents in document library inside all folders

Hi All,

Many times we require getting all documents in the entire document library including sub folders. For this we need to use the ViewAttributes property on SPQuery object and set it to specify Scope=\"Recursive\

If we don’t do this, then result we will get it all documents from the top folder only.

Here is a simple way, we will achieve this.

SPList objList = objWeb.Lists["{name of the doc lib}"];

SPView objView = objList.Views["name of the view"];

SPQuery objQuery = new SPQuery(objView);

objQuery.ViewAttributes = "Scope=\"Recursive\"";

SPListItemCollection objItemColl = objList.GetItems(objQuery);


Sometimes we may require returning the result from specific folder inside the document library.

At this time, we need to use SPFolder class and set the SPQuery object’s Folder property to the object of SPFolder.

Here is a way.

SPFolder objFolder = objList.RootFolder.SubFolders["name of the folder"];
objQuery.Folder = objFolder



That is it. Your job is done.
Read More…

Saturday, June 27, 2009

Understanding of securing objects in WSS 3.0

Hi All,

There is a way how we can secure the object in WSS. When I say secure it means objects exposes several methods which will allow us to determine the rights or the permission related stuff on list / document library level, item level and individual site level.

Here we are talking about understanding DoesUserHavePermissions method on these securable objects.

Let us take an example one by one. First we will talk about permission checking on site level.

Let’s say we have taken the reference of current site and it is stored in objWeb, then this method checks if the current user has permission to View the List Items?

if(objWeb.DoesUserHavePermissions(SPBasePermissions.ViewListItems))
{
// your code goes here
}


Second, we talk about the same permission set but on the list level.

Let’s say we have taken the reference of lstContacts and wants the check for the same view list items permission, then

if(objList.DoesUserHavePermissions(SPBasePermissions.ViewListItems))
{
// your code goes here
}


And at last the same with each item of list / doc lib as SPListItem object objItem.

if(objItem.DoesUserHavePermissions(SPBasePermissions.ViewListItems))
{
// your code goes here
}


This method actually does not throw the exception if the permission is not there for the user, but there is one more method which does exactly the same thing, but throws the exception if the permission is not there for the user.

e.g. objWeb.CheckPermissions(SPBasePermissions.ViewListItems)

Above method checks the permission for the current user, but sometimes you may also require to check the same permission for some other user, well in that case, use the same method with overloaded method which has first parameter as string which takes the Login with domain name.

objItem.DoesUserHavePermissions({loginname}, SPBasePermissions.ViewListItems))

Well sometimes i think, is the name of this method correct? I mean shouldn't it be DoesUserHasPermission? if we see real grammer? your thoughts on this, readers? :)

Thank you
Read More…

Friday, June 19, 2009

Using SPWebApplicationBuilder class for creating Web Application programmatically

Hi All,

We all know that the Web Application is the main container for all site collections. Ultimately it is the whole and sole of all sites created later on.

So in this article, we will learn how to create Web Application programmatically with SPWebApplicationBuilder Class. When we instantiate the object of SPWebApplicationBuilder class, it automatically provides the default values for the required settings.

However there are many other properties that you can set. These are the same properties that we set from UI in central administration at the time of creating web application.

Here is a list of some properties. You can find all properties from of course MSDN.

ApplicationPoolId. – GUID of the application pool that will get created for web application.

ApplicationPoolUsername. – User name of the windows account under whom web application will run.

ApplicationPoolPassword- Password of the windows account under whom web application will run.

CreateNewDatabase. – Gets or sets the Boolean value indicating to create the database for web application or not.

DatabaseName – Name of the database

Port – Port number on which web application runs

Here is a way we will proceed to create web application. First instantiate the SPWebApplicationBuilder class object.

Then you can set different properties. Here I am setting only port number.

Then get the SPWebApplication class object by calling the create method on SPWebApplicationBuilder object.

Here is a short code.

SPWebApplicationBuilder objWebAppBuild= new SPWebApplicationBuilder(SPFarm.Local);
objWebAppBuild.Port = 8880;
SPWebApplication objWebApp= objWebAppBuild.Create();
objWebApp.Provision();


Just to check one important thing is under which account code is running.

That’s it. Your job is done.
Read More…

Thursday, June 18, 2009

How to customize the Theme in SharePoint

Hi All,

Many times we require customizing theme of SharePoint site. For Creating Theme we first need to create one folder in the 12\TEMPLATE\THEMES Folder under 12 hive structure.

Copy any of the folders from that THEMES folder and give that new folder your appropriate unique name. Let’s say we give the new folder “XTheme” as name of it. Ultimately this folder will contains css files, images , color of font and all.

Now you need to find one file in the folder that you have copied, check for .inf file and rename it to the foldername.inf.

Now open this .inf file and give the same name to the to the title in the [info] and [titles] sections of the file.

Now modify and make the changes according to your business need. Colors, styles, images and everything.

You now also need to add one image especially for preview purpose when you will view this from Site Theme option.

Copy your image to the 12\TEMPLATE\IMAGES folder. Let’s say we call it as XTheme.gif

Now find one more file at this location 12\TEMPLATE\LAYOUTS\1033 which is SPTHEMES.xml. You need to add this THEME as templates collection like this.

<Templates>
<TemplateID>XTheme</TemplateID>
<DisplayName> XTheme </DisplayName>
<Description>This is my new THEME</Description>
<Thumbnail>images/XTheme.gif</Thumbnail>
<Preview>images/XTheme.gif</Preview>
</Templates>


Now reset the IIS, I guess it will not require but then also just to be on safer side, reset the IIS and now you should be able to change the Site Theme to the your custom theme.

That’s it. Your job is done.
Read More…

Sunday, June 14, 2009

Understanding Feature Stapling

Hi All,

In this article, we will discuss something about feature stapling.

If I have to tell you in a very simple manner what we mean by feature stapling then my answer would be a feature that can attached to multiple site templates as well as multiple custom site templates at one go.

That means, let’s say we create one simple feature of creating list with few columns and if we want to have this list created every time blank site or team site is created, then we can register this feature to be used in team site and blank site, so that whenever we create team site or blank site, the list gets created.

If you want to have the feature available in every type of site templates then also you can do it. That means you select any templates then also that list will get created in it. We will call it as Global Site availability for the feature.

Here is a way we can achieve this.

Take a look at this XML. We will already have the feature that we want to have it in Team Site and Blank Site. So we will create one feature for achieving the feature stapling and its elements.xml is mentioned here.

<Elements xmlns=http://schemas.microsoft.com/sharepoint/>
<FeatureSiteTemplateAssociation
Id=”{GUID of the feature that you want to make available in Team Site and Blank Site}”
TemplateName=”STS#0” />

<FeatureSiteTemplateAssociation
Id=”{GUID of the feature that you want to make available in Team Site and Blank Site}”
TemplateName=”STS#1” />
</Elements>

Here STS#0 and STS#1 refer to Team Site and Blank Site respectively.

That is it, Deploy this feature and activates it at Site Collection level or site, web application or farm level.

From Next time, if you create the Team Site and Blank Site, the feature that you mentioned in stapling will be there in that site created.

If you want this feature to be there in every site template, then just one change you need to make and the change is as follows.

TemplateName attribute value will be “GLOBAL#0”. That’s it.
Read More…

Friday, April 17, 2009

Creating Custom Tool Part

Hi All,

First let me just highlight you what do we mean by toolpart. When you create your webpart and place it on your page and when you modify the webpart, at the time what appears right hand side is a panel and if you want to place any specific control there as a property, then we can create toolpart for the webpart.

Here we go with the example. Let’s say that we already have one web part which inherits from Microsoft. Sharepoint.WebpartPages.Webpart

So all you need to do is this.

Step 1: First you need to define the property. At the time of defining the property, do keep in mind what kind of a property is that, is it personal property (per user based) or shared property (common for every user)


Check out its two attributes named WebPartStorage and PersonalizationScope which will tell you the scope (personal or shared)

Let’s say we define one property called CustomerName

private string strCustomerName = string.Empty;

[Browsable(false),//Display the property in property pane
Category("CustomToolPart"),//Create a Customer Details category in property pane
DefaultValue(""),//Assign a default value
WebPartStorage(Storage.Personal),//Make available in both personal and shared mode
Personalizable(PersonalizationScope.User),
FriendlyName("Customer Name"),//The caption display in property pane
Description("The name of the customer")]//The tool tip
public string CustomerName
{

get
{
return strCustomerName;
}
set
{
strCustomerName = value;
}
}


Just like this, as many properties that you want to define, define them in the code of your webpart class.


Now is the time of override one method which is GetToolParts(), but before proceeding here let us understand these two classes.

(1) WebPartToolPart – It actually represents a tool part that can be used to show and modify Web Part base class properties.

And

(2) CustomPropertyToolPart – Same as above, the only difference is that it is used to show and modify the custom propoerties that we have defined in the webpart class that are not the webpart base class propoerties.

So coming back to our GetToolParts method. Here toolpartclass is class that we are soon going to create.


public override ToolPart[] GetToolParts()
{
ToolPart[] toolparts = new ToolPart[3];

WebPartToolPart wptp = new WebPartToolPart();

CustomPropertyToolPart custom = new CustomPropertyToolPart();

toolparts[0] = wptp;

toolparts[1] = custom;

toolparts[2] = new {toolpartclass}

return toolparts;
}



Actually this method returns you the instance of the different toolparts that comes right hand side when you modify the webpart.

Here as you can see, we have got webparttoolpart and also custompropoertytoolpart along with the toolpart class that soon we are going to develop.

Ok, let’s develop and create ToolPart class which will have RenderToolPart and ApplyChanges method.

Create a class which inherits from Microsoft.Sharepoint.WebpartPages.ToolPart.

Declare a variable which will be the name of the control renders in toolpane

private string strHTMLinputControlName = "Mycontrol";

Write down the RenderToolPart method which is vey important.

protected override void RenderToolPart(HtmlTextWriter output)

{

// Establish a reference to the Web Part.

// CustomWebPart is the web part class name.

{webpartclassname} customWebPart =

(webpartclassname)this.ParentToolPane.SelectedWebPart;

//Create the input control

output.Write("Enter the customer name: ");

output.Write("<input name= '" + strHTMLinputControlName);

output.Write("' type='text' value='" +

SPEncode.HtmlEncode(customWebPart.CustomerName) + "'><br>");

}


Here if you observe, we have first taken the reference of the webpart class for which we are creating this toolpart. So parentToolPane.SelectedWebPart will be the webpart for which we are creating toolPart.

Now write down ApplyChanges method which will be called when we press OK or Apply after applying property in propoertypane of webpart.

public override void ApplyChanges()
{

// apply property values here

//Get a reference to the web part class

{webpartclassname} cw1 =

(webpartclassname)this.ParentToolPane.SelectedWebPart;

//Pass the custom text to web part custom property

cw1.CustomerName = Page.Request.Form[strHTMLinputControlName];

}


Here as you can see, we have gain taken reference of webpart class for which we are creating propoerty with custom toolpane. And then take the entered data with request.form and passing control’s name and setting to the propoerty defined in the webpart class which is CustomerName in our case.

That’s it. You are done with your job. All you have to do is go to your webpart page. Edit the webpart in pursonalize this page mode as because we have defined our propoerty as per user basis, edit webpart, click on modify my webpart and then as you can see for each different user will be able to set their own customerName.

And then simple, refer this.CustomerName as part of code in your webpart class, per user bases you will get the values set by individual user.

Have a fun. Try to explore toolpart class more.

Thank you.
Read More…



Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com