Microsoft SharePoint 2010 makes it easier for people to work together. Here‘s an opportunity to test your knowledge on Microsoft SharePoint 2010. Participate in the Quiz Contest and you stand a chance to win a Windows Mobile and USB Pen Drives.
Click here for more details.
Tuesday, March 15, 2011
SharePoint Webpart Custom Properties with Default Value
Most of the sharepiont custom development involves creating custom webparts. There could be scenarios where some of the values like connection string, site url, list/library name are configurable by Admin/End User and changeble depending on the requirement. To achieve this for SharePoint webpart, the values can be configured using webpart properties. Any number of webpart properties can be added to the webpart with one or more categories to differenciate. Property value can be modified/changed by modifying the shared webpart.
Webpart property default value can be set using DefaultValue property, as shown below. Note that to set the default value, the value should be stored in a constant variable, otherwise it doesn't work properly.
Webpart property default value can be set using DefaultValue property, as shown below. Note that to set the default value, the value should be stored in a constant variable, otherwise it doesn't work properly.
//Namespaces required
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
const string const_listName = "ListName";
private string _listName = const_listName;
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[Category("My Category")]
[WebDisplayName("List Name")]
[WebDescription("Provide list name to get all the items.")]
[DefaultValue(const_listName)]
public string ListName
{
get
{
return _listName;
}
set
{
_listName= value;
}
}
Monday, March 14, 2011
SharePoint Write Custom Error to Log file (ULS Error Logging)
Most of the requirements in sharepoint applications needs custom development i.e., web parts, workflows, event recievers, timer jobs etc.,
And we might need to write the exception/error details to log somewhere(list or text file in the file sytem).
As all the sharpoint error details are logged in 12 hive Log files, even we can write our custom error details to the same log file by using the ULS logging.
And we might need to write the exception/error details to log somewhere(list or text file in the file sytem).
As all the sharpoint error details are logged in 12 hive Log files, even we can write our custom error details to the same log file by using the ULS logging.
SPSecurity.RunWithElevatedPrivileges(delegate()Note: the logging code statement should be run under RunWithElevatedPrivileges, if the code is executable by end user.
{
//Reference of Microsoft.Office.Server.dll needs to be added
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("My Custom Error - Message:{0} || Stack Trace:{1}", ex.Message, ex.StackTrace);
});
Wednesday, March 9, 2011
Javascript Get Running Formatted DateTime
To show the formatted running datetime on the browser/page there is no straight way. But using javascript we can achieve this by manipulating with each unit in the datetime.
The following is the code to show the formatted running date time.
The following is the code to show the formatted running date time.
Html div tag to show/render the running time.
Tuesday, March 8, 2011
SharePoint PictureLibrary Thumbnail Url Vs Picture Url
I had hard time to get the complete Url of the picture as well thumbnail directly (using any property) inserad of managing with server relative/absolute url, thumbanil folder /t and the picture name.
But we have full control through SPObject Model(SPBuiltInField class) to get the picture/thumbnail Url directly.
To get the absolute, relative Urls of the picture the Url can be managed as below.
But we have full control through SPObject Model(SPBuiltInField class) to get the picture/thumbnail Url directly.
SPList spList = web.Lists["ImagesLibrary"];The above Urls are the full Urls of the thumbnail and picture respectively.
SPListItem item = spList.Items.GetItemById(itemID);
//Thumbnail Url
string thumbnailUrl = item[SPBuiltInFieldId.EncodedAbsThumbnailUrl].ToString();
//Picture Url
string pictureUrl = item[SPBuiltInFieldId.EncodedAbsUrl].ToString();
To get the absolute, relative Urls of the picture the Url can be managed as below.
Uri uri = new Uri(thumbnailUrl);
string relativePath = uri.AbsolutePath;
Subscribe to:
Posts (Atom)