Search This Blog

Saturday, October 24, 2009

Hide Save button on Multipage Survey Page

To hide save button on mutipage survey following javascript can be used. Insert following javascript block within PlaceHolderMain after <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> line of NewForm.aspx & EditForm.aspx page of the Survey

<script type="text/javascript" >
_spBodyOnLoadFunctionNames.push('hideSave');

function hideSave()
{
var tags=document.getElementsByTagName('input');
alert(tags.length);
for(var i=1; i<tags.length; i++)
{
if(tags[i].value=='Save')
{
tags[i].style.visibility='hidden';
}
}
}
</script>

Saturday, October 10, 2009

Show PDF icon in SharePoint Library view

To show the PDF icon (or any other icon) in SharePoint Document Library view do following:
1. Find 16x16 icon file, say pdficon.gif and upload it under \12\TEMPLATE\IMAGES folder
2. Then open \12\TEMPLATE\XML\DOCICON.XML and in the "By Extension" section add the following configuration line:
< key="pdf" value="pdficon.gif">

Restart IIS and now PDF icon should appear against PDF files in any document Library.

Do the same for other file types also.

Monday, August 17, 2009

Add ..more hyperlink to Announcement Webpart


Description: I was having a request from end user to display ..more hyperlink the annoucement webpart, which redirects to respective item display page.

Solution: Create a custom XSL template for Content Query Webpart. Then use Content Query Webpart to display Announcement content using Custom XSL template. Follow these steps:

1. Open root site of web, go to View All Site Content---> Style Library -->XSL Style Sheets & locate the file ItemStyle.xsl. Open ItemStyle.xsl with any text editor & insert following template named AnnouncementStyle at the bottom before </xsl:stylesheet> tag :

<xsl:template name="AnnouncementStyle" match="Row[@Style='AnnouncementStyle']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="@Title"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>

<div id="linkitem" class="item">

<div class="link-item">
<NOBR><div><a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
<xsl:value-of select="$DisplayTitle"/>
</a></div>
<div class="description"> By <xsl:value-of select="@Author"> </xsl:value-of> <xsl:value-of select="ddwrt:FormatDate(string(@Created), 1033, 2)"> </xsl:value-of></div></NOBR>
<div class="description">
<xsl:value-of select="substring(@Body,1,200)" disable-output-escaping="yes"/>
<a href="{$SafeLinkUrl}" title="Read more.."> ...more
</a>

</div>
</div>
</div>
</xsl:template>

2. Add a Content Query Webpart on the page where you want to display the announcement & set Query-->Source to Show items from the following list: & Select the Announcement List you want to display. Now, export the webpart to .webpart file on your PC. Open exported .webaprt file & locate the tag <property name="CommonViewFields" type="string">
replace above line with
<property name="CommonViewFields" type="string" >Body, text; Created, text;FileDirRef,text </property>

3. Now, import above modified .webpart file & add this CQW webpart to page & remove previously added CQW.
4. Modify above CQ webpart & set the Presentation-->Item Style to AnnouncementStyle.

Result: Finally CQW should display announcements like following:

Tuesday, April 14, 2009

SharePoint Designer 2007 is available for free download

Starting April 1, 2009 SharePoint Designer 2007 is available as a free download. You can find a
lot more information at the SharePoint Designer site including:

Download SharePoint Designer from here

Sunday, April 5, 2009

SharePoint WebPart Property Attributes

SharePoint WebPart Property Attributes

Following are Property Attributes:

WebBrowsable [WebBrowsable(True)]
"Indicates whether the designated property of a Web Parts control is displayed in a PropertyGridEditorPart object." (MSDN)
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webbrowsableattribute.aspx

WebPartStorage [WebPartStorage(Storage.Personal)]
This attribute specifies what type of storage options the WebPart will make use of. The most common is Storage.Personal. "This property can be personalized by individual users. Its WebPartStorageAttribute value is Storage.Personal, which specifies that the property can be stored on a per-user basis. Only users with the Personalize Web Part pages right can set this property." (MSDN)
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpartstorageattribute.aspx

Personalizable [Personalizable(true)]
Allows users the ability to personalize settings for the WebPart.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.personalizableattribute.aspx

WebDispayName [WebDisplayName(string)]
Defines the Friendly Name for a property of a WebPart control. This is the name that will show up in the editor screen.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webdisplaynameattribute.aspx

WebDescription [WebDescription(string)]
Defines the string value to use as a ToolTip for a property of a Web Parts control. (MSDN)
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webdescriptionattribute.aspx

SPWebCategoryName [SPWebCategoryName(string)]
Defines the friendly or localized name of the category of a property in the CustomPropertyToolPartcontrol inside the ToolPane.
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.spwebcategorynameattribute.aspx

ConnectionProvider [ConnectionProvider(string)]
Identifies the callback method in a server control acting as the provider in a Web Parts connection, and enables developers to specify details about the provider's connection point. (MSDN) This is used to create connectable WebParts.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.connectionproviderattribute.aspx

ConnectionConsumer [ConnectionConsumer(string)]
Identifies the callback method in a server control acting as the consumer in a Web Parts connection, and enables developers to specify details about the consumer's connection point. (MSDN) This is used to create connectable WebParts.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.connectionconsumerattribute.aspx

Below is an example of how to use these attributes in your WebPart code.

[WebBrowsable(true),
Personalizable(true),
WebPartStorage(Storage.Personal),
WebDisplayName("Caption)"),
WebDescription("Set Caption"),
SPWebCategoryName("Other Options")]
public string Caption
{
get

{

return caption;

}
set

{

caption= value;

}
}

Properties will display in different formats according to the property type. (as displayed below)

Property TypeDisplay as
BoolCheck box
DateTimeText box
Enum Dropdown box
int / stringText box


Elapsed Counter Webpart for MOSS/Sharepoint 2007



Background: One of our clients wanted an Elapsed Counter Webpart, which shows the elapsed days & time from a specified start date. Start date should be persisted & user should be able to sett the value of Start Date & Caption string.


Solution: I developed a webpart using VS 2005 with help of javascript. Javascript code is used to display the ticking clock. Clock value is initilized using StartDate webpart property & user can set the value of startDate property at runtime. Another property named Caption is used to set the caption of counter. There are two approach to include the javascript resource(file) in webpart.
1: add as embedded resource(the case is have used in this solution). Advantage of this approach is you need not to deploy the js file separately in sharepoint environment. Bad part of this approach is you have to recompile entire solution if there any change in javascript [I have used this approach].
2: deploy to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS & refer the file there.

Step 1: Create new webpart project using VS 2005[C# is the language in my case] & add following code in webpart(.cs file)

using System;
using System.Drawing ;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace Safety
{
[Guid("b1ac74f7-0edf-4fca-90bd-51e109d4950b")]
public class SafeHours : System.Web.UI.WebControls.WebParts.WebPart
{
Label lblError;
System.DateTime startDate=DateTime.Now ;//default value for startDate
string caption = "Days without L.T.A.";//default value for caption

public SafeHours()
{
}

//add Caption property & attributes
[WebBrowsable(true),
XmlElement(typeof(System.DateTime)),
Personalizable(PersonalizationScope.Shared),
SPWebCategoryName("Other Options"),
WebPartStorage(Storage.Personal),
FriendlyName("Caption"),
WebDescription("Set Caption")]
public string Caption
{
get
{
return caption;
}
set
{
caption = value;
}

}

//add Start Date property & attributes
[WebBrowsable (true),
XmlElement(typeof(System.DateTime)),
Personalizable(PersonalizationScope.Shared),
SPWebCategoryName("Other Options"),
WebPartStorage(Storage.Personal),
FriendlyName("Start Date-Time (format: mm/dd/yyyy hh:mi:ss AM"),
WebDescription("Set Start Date Time")]
public System.DateTime Startdate
{
get
{
return startDate;
}
set
{
startDate = value;
}
}


protected override void CreateChildControls()
{

try
{
//embed java script file(dont' forget append the namespace of webpart before file name)
Page.ClientScript.RegisterClientScriptResource(GetType(), "Safety.elapsed.js");
base.CreateChildControls();
Literal litData = new Literal(); //Literal control to write the control values
Literal litDataTemp = new Literal();//Tempporary Literal control to write the control values

DateTime ts = this.startDate; //get Start date from webpart property

//here we assign the start date values to named td(s) of dummy table be used by Javascript code
(replace [ with < & ] with >)

litDataTemp.Text = "[table style='font-size: 1 pt; width: 479px; color: white'] [tr] "+
"[td id='startYear_" + this.ID + "' style='height: 4px; font-size: 1pt;']" + ts.Year +
"[/td][td id='startMonth_" + this.ID + "' style='height: 4px; font-size: 1pt;']" + ts.Month +
"[/td][td id='startDay_" + this.ID + "' style='height: 4px; font-size: 1pt;']" + ts.Day +
"[/td][td id='startHour_" + this.ID + "' style='height: 4px; font-size: 1pt;']" + ts.Hour +
"[/td][td id='startMinute_" + this.ID + "' style='height: 4px; font-size: 1pt;']" + ts.Minute +
"[/td][td id='startSecond_" + this.ID + "' style='height: 4px; font-size: 1pt;']" + ts.Second +
"[/td][/tr][/table]";

//add dummy table
this.Controls.Add(litDataTemp);

//add another table which shows the counter (replace [ with < & ] with >)

litData.Text = "[table style='width: 500px'] [tr] [td id='elapsedDays_" + this.ID + "' style='width: 700px; " +
"background-color: steelblue; font-weight: bold; font-size: 18pt; vertical-align: middle; " +
"color: white; height: 35px; text-align: center;'][/td][/tr][tr] " +
"[td id='elapsedHours_" + this.ID + "' style='width: 700px; background-color: lightsteelblue; " +
"font-weight: bold; font-size: 18pt; vertical-align: middle; color: black; height: 35px; " +
"text-align: center;'][/td][/tr] [/table]";
//add counter table
this.Controls.Add(litData);

//define new HtmlGenericControl to call the javascript function
System.Web.UI.HtmlControls.HtmlGenericControl c = new System.Web.UI.HtmlControls.HtmlGenericControl("script");
c.Attributes.Add("language", "javascript");
//call javascript function
c.InnerText = "showElapsedTime('" + this.ID + "','" + this.caption + "')";
//add javascript control
this.Controls.Add(c);
}
catch(Exception ex)
{
//add label to show the error
lblError = new Label();
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = ex.Message;
this.Controls.Add(lblError);
}

}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
}
}

Step 2: Javascript: Add a javascript file (elapsed.js in my case) in the root folder of webpart project & add following script:

function showElapsedTime(wid,caption)
{

var startYear = document.getElementById("startYear_"+wid).innerHTML;// initialize start year using named td of temp table ;
var startMonth = document.getElementById("startMonth_"+wid).innerHTML;//initialize start month using named td of temp table
var startDay = document.getElementById("startDay_"+wid).innerHTML;// initialize start day using named td of temp table
var startHour = document.getElementById("startHour_"+wid).innerHTML;//initialize start hour using named td of temp table
var startMinute = document.getElementById("startMinute_"+wid).innerHTML;//initialize start minutes using named td of temp table
var startSecond = document.getElementById("startSecond_"+wid).innerHTML;//initialize start seconds using named td of temp table
var startDate = new Date();
startDate.setYear(startYear);
startDate.setMonth(startMonth-1);
startDate.setDate(startDay);
startDate.setHours(startHour);
startDate.setMinutes(startMinute);
startDate.setSeconds(startSecond);

//alert(startDate);
var rightNow = new Date();
//calculate elapsed time
var elapsedTime = rightNow.getTime() - startDate.getTime();

//calculate elapsed days
var one_day=1000*60*60*24;
var elapsedDays = Math.floor( elapsedTime / one_day );
var milliSecondsRemaining = elapsedTime % one_day;

//calculate elapsed hours
var one_hour = 1000*60*60;
var elapsedHours = Math.floor(milliSecondsRemaining / one_hour );
milliSecondsRemaining = milliSecondsRemaining % one_hour;

//calculate elapsed minutes
var one_minute = 1000*60;
var elapsedMinutes = Math.floor(milliSecondsRemaining / one_minute );
milliSecondsRemaining = milliSecondsRemaining % one_minute;

//calculate elapsed seconds
var one_second = 1000;
var elapsedSeconds = Math.round(milliSecondsRemaining / one_second);

//write the out values to couter table
document.getElementById("elapsedDays_"+wid).innerHTML = caption+ elapsedDays ;
document.getElementById("elapsedHours_"+wid).innerHTML =elapsedHours +"Hrs : " + elapsedMinutes + "Min : " + elapsedSeconds + "Sec";

//set function timeout recurrsively
t = setTimeout("showElapsedTime('"+wid+"','"+caption+"')",1000);

}

Step 3: In solution explorer right click on elapsed.js --> properties & set Built Action to Embedded Resource.

Step 4: Build the solution & deploy to sharepoint server.


Step 4: Add the webpart to a webpart page & set Caption & Start Date-time properties in Webpart properties toolpane as given below:


Output: Here is the output

Sunday, March 22, 2009

Best Practices : WSS 3.0 & SharePoint 2007

Best Practices Resource Center for SharePoint Server 2007 (http://technet.microsoft.com/en-us/office/sharepointserver/bb736746.aspx)

A single source that you can find best practices around WSS 3.0 and Microsoft Office SharePoint Server 2007.

Tuesday, March 17, 2009

Sharepoint Tips

Tip#1: Do not user spaces & special characters in sharepoint list field name. It may create problem when you are accessing the data using Sharepoint object model & playing with CAML.

Tip#2: To view Sharepoint Webpart page in maintenance view append ?contents=1 at the end of URL.
For example: http://sevrer:1000/site1/webpartpage1.aspx?contents=1 will open Webpart page webpartpage1.aspx in maintenance view.

Tip#3: Getting XML Data From a SharePoint List – The Easy Way

Tip#4: To view Sharepoint Workflow History List[All workflow history items] use this path:
http://ServeName:Port/Lists/Workflow%20History/AllItems.aspx

Sunday, February 22, 2009

SPD Workflow "Error Updating List Item" while setting the value of people/user field

Problem: I was calling a SPD workflow on a custom list. Whenever workflow is called upon new list item creation, following error error logged in the workflow history in & workflow inrterrupted:

2/22/2009 1:30 PM Error System Account Error updating a list item Unknown error
2/22/2009 1:30 PM Error System Account An error has occured in Expert Contact Request.

Cause: In the workflow I was setting the value of the people/group field by picking up the workflow creator's value. If I remove this action then workflow is working fine. Means, SPD workflow is unable to set the value of Person/Group field.

Solution: While setting the value of People/Group field, don't set the value of person/people field directly, instead build a dynamic string and append -1;# to the People/Group name. Finally set the output of the dynamic string to people/group field.
Example:
-1;#domain\username

So, if you are setting the field value to “company\MyUser1”, instead set the value to:
“-1;#company\MyUser1”. The -1 is constant.


Thursday, February 12, 2009

How to change DNS or URL of a MOSS 2007 site ?

Scenario:
I developed a sharpoint site on server[server1] having default URL "http://server1:1515/sites/site1". Sharepoint server machine is member of a domain xyz.com. End user of this intranet site is member of another domain in the intranet. When user is trying to browse this intranet site FQDN [http://server1.xyz.com:1515/sites/site1], then s/he is getting sharepoint error saying "File not found".

Solution:
  • Open Sharepoint Central Admin & go to Operations tab
  • Under Global configuration heading select Alternate access mappings.
  • Select the desired web application i.e. http://server1:1515 (in this example)
  • On Edit Internal URLs page set the change the value of "http://server1:1515" to "http://server1.xyz.com:1515".
  • Now this site[http://server1.xyz.com:1515] will be accessible throughout the intranet from any domain.

Sunday, February 1, 2009

How to edit publishing portal pages?

I was trying to edit the portal web part pages using the sharepoint designer, but every time I select Edit with Microsoft Office Sharepoint Designer, I got following message:

This page can not be edited in sharepoint designer. You can edit the content in the browser, or edit he corresponding page layout in Sharepoint Designer.

Solution: Explore the site in Sharepoint Designer and navigate to Page library(Pages) & locate the page you want to edit. Right click on the desired page and Select Detach from Page Layout. Now you have page ready to be edited. Once, you finish the page editing then do the reverse operation i.e. Reattach to Page Layout.

Caution: Edit page layout will lead to change the Layout of every page using same layout.

Trick to edit sharepoint ListViewForm using browser

Here is trick for editing the sharepoint new item form/edit form/display form using browser.

Add Web Parts/Browse ToolPaneView=2
Add Web Parts/Search ToolPaneView=3
Edit Mode mode=edit
View Mode mode=view
Shared Mode PageView=Shared
Personal Mode PageView=Personal

example:
1. To edit default new item form/edit form/ display form e.g. NewForm.aspx use this:
/sitepath/newForm.aspx?ToolPaneView=2

2.
To edit default new item form e.g. NewForm.aspx use this:
/sites/SCEM/Pages/Default.aspx?mode=edit&pageview=Shared

regards,
Mohd. Shamim

I Joined SABIC...

I joined the SABIC(Saudi Basic Industries Corporation) on 17/01/09 as Sharepoint Consultant.