Posts

Showing posts from 2011
My new blog present here.

Featured Post

Insights into Sitecore Search: A Definitive Introduction

A key component of digital experience management is effective information retrieval. A simplified approach is required for websites, applications, and platforms containing a lot of material so that consumers can easily get the data they require. This need is met by Sitecore, a well-known name in the field of digital experience platforms (DXPs), which provides powerful and comprehensive search functionality. We will travel into the realm of Sitecore Search in this article, learning about its capabilities, architecture , and the enormous value it offers both developers and end users. Introduction to Sitecore Search    A headless content discovery platform powered by AI , Sitecore Search enables you to build predictive and custom search experiences across various content sources. To extract and index you

Get UserProfile Object of Logged-in User

In this article, I will explain how to get UserProfile object for Logged-in User (current user). //Function Call UserProfile objUserProfile= GetProfileOfCurrentUser(SPContext.Current.Web.CurrentUser.LoginName) public UserProfile GetProfileOfCurrentUser(string accountName) { UserProfile profile = null; try { if (string.IsNullOrEmpty(accountName)) { return null; } SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite site = SPContext.Current.Site; ServerContext context = ServerContext.GetContext(site); UserProfileManager profileManager = new UserProfileManager(context); if (!profileManager.UserExists(accountName)) { profile = null; } profile = profileMan

Event receiver to update an item's in list

How to update Created By and Modified By fields in sharepoint list using C# In this article I will explain, how to update list item in event receiver. In event receiver, I will update Created By /Modified By/Title metadata of list item. Code: public override void ItemUpdated(SPItemEventProperties properties) { int userID=0; string userNTID = "WIN\AMITKUMAR"; SPSecurity.RunWithElevatedPrivileges(delegate() { SPListItem CurrentItem = properties.ListItem; CurrentItem.Web.AllowUnsafeUpdates = true; CurrentItem.Web.Site.AllowUnsafeUpdates = true; // In the next statment i am updating CreatedBy(Author) filed with SystemAccount CurrentItem["Author"] = CurrentItem.Web.Site.SystemAccount.ID; //CreatedBy //We can also update CreatedBy(Author)/ModifiedBy(Editor) field with Any user account FindUserIDByNTID(userNTID, CurrentItem.Web.Site, ref userID);

Get unique value from Array (String/Integer):

Problem: In one of my project, I am getting values from one datasource in the form of .net Array. In the .NET Framework 3.5 there is a function called Distinct(). This Distinct() function return unique values from Array. This function works fine in the case of integer array. In string array, it not able to handle case sensitivity. If all items in the string array in same case, then it will work fine. Due to this, I was facing problem in getting unique value from String Array. Resolution: To Solve this problem, I have created functions, which used Stringcomparison. InvariantCultureIgnoreCase. .NET Framework 3.5: It is one line of code. //If integer array int [] intArr={5,2,3,3,5}; intArr = intArr.Distinct().ToArray(); // Output : intArr ={5,2,3} //If string array string [] strArr={“Amit”,”Amit”,”Kumar”,”Kumar”}; strArr = strArr.Distinct().ToArray(); //Output: strArr ={“Amit”,,”Kumar” } string [] strArrCase={“Amit”,”AMIT”,”Kumar”,”KUMAR”,”Amit”,”Kumar”}; strArrCa

Render(Parse) XML using XSLT

Requirement: The requirement is to render xml data into a page. Resolution: We can perform this task by following ways: 1. Read xml file using C#.Net and iterate the xml node. At the time of iteration, render data from xml to page. 2. Use the XSL. In this approach, create .XSLT file, which store the formatting in the form of HTML/CSS. By using XSL, we can separate the data rending from the data itself. Example to render (parse) xml using xslt: Save given xml in to file called "myNavigation.xslt":

How to read XML using LINQ

LINQ is a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities. One of the big programming model improvements being made in .NET 3.5 is LINQ. "LINQ", stands for .NET Language Integrated Query. LINQ supports a rich extensibility model that facilitates the creation of efficient domain-specific providers for data sources. .NET 3.5 ships with built-in libraries that enable LINQ support against Objects, XML, and Databases. “Microsoft original motivation behind LINQ was to address the impedance mismatch between programming languages and database.” What is LINQ to XML? LINQ to XML is a built-in LINQ data provider that is implemented within the "System.Xml.Linq" namespace in .NET 3.5. Formerly LINQ is XLinq. It means Queries performed against the XML sourc

Highlight the link(href Tag/HTML link Tag) on click:

Highlight the link(href Tag/HTML link Tag) on click: With the help of style sheet(CSS), we can highlight the link after click. Write below mentioned styles in STYLE tag before HEAD Tag of page: a:link {font-size: 11px;color:green;text-decoration: none} /* unvisited link */ a:visited {font-size: 11px;orange:orange;text-decoration: none} /* visited link */ a:hover {font-size: 11px;text-decoration: underline;color:#FF00FF;} /* mouse over link */ a:active {font-size: 11px;color:orange;text-decoration: none} /* selected link */ Write below mentioned HTML in BODY Tag of page: Amit Kumar1 Amit Kumar2 Amit Kumar3

How to get Publishing Page Meta Data (Column Value) in Sharepoint

Requirement: The requirement is to identify status (Draft/Approved/Checkout/Pending/Published) of page in Pages library and also fetch the metadata of page using SharePoint Ojbect Model in Publishing Web. Resolution: With the help of PublishingWeb class (Microsoft.SharePoint.Publishing), we can access different components of Published Web site like Pages document library, Published site navigation bar and etc. The PublishingWeb class provides publishing behavior for an SPWeb instance that supports publishing. This class cannot be inherited. Namespace: Microsoft.SharePoint.Publishing Assembly: Microsoft.SharePoint.Publishing (in microsoft.sharepoint.publishing.dll) In this example we will identify status (Draft/Approved/Checkout/Pending/Published) of page and access metadata of Pages from Pages Library in Publishing Web: using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office.

Upload (Import) data from excel (spreadsheet) file to SharePoint list using c#

Upload (Import) data from excel (spreadsheet) file to SharePoint list using c#: When we have data in excel format and want to import that data to a SharePoint list, then how to do. By default SharePoint will provide us an option to edit in spreadsheet or download list items in spread sheet. But, it doesn't have an option to import the excel data to SharePoint list. To resolve this problem, I have created web part. In this web part, I am using SharePoint list called “Employee”. The name of columns are Tile and LastName. With the help of this web part, user will enter the data in the excel and then give the path of the file in the input box present in the page. Now instead of uploading the whole excel file into a document library the code will read the file and update the list with the data present in the excel file. The web part code is: using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Data; using System.Xml; using System.Xml.Serializ

Get changed user profiles in SharePoint using C#

Get all the user profiles/properties which are modified since yesterday date or any datetime interval: With the help of UserProfileManager class (Microsoft.Office.Server.UserProfiles), we can access properties of user profile and changed profile which are modified since yesterday date or any datetime interval. In this example we will access different components of UserProfileManager : using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office.Server.UserProfiles; using Microsoft.SharePoint; using System.Web; using System.Collections; namespace UserProfilesOMApp { class Program { static void Main(string[] args) { using (SPSite site = new SPSite("http://amitkumarmca04.blogspot.com")) { ServerContext context = ServerContext.GetContext(site); UserProfileManager profileManager =

Accessing SharePoint Publishing site Navigation (Global Navigation bar) using C#

Accessing SharePoint Publishing site Navigation (Global Navigation bar) using C#: With the help of PublishingWeb class (Microsoft.SharePoint.Publishing), we can access different components of Published Web site like Pages document library, Published site navigation bar and etc. In this example we will access different components of Published site: using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office.Server.UserProfiles; using Microsoft.SharePoint; using System.Web; using Microsoft.SharePoint.Navigation; using Microsoft.SharePoint.Publishing; namespace GetPublishedData { class Program { static void Main(string[] args) { using (SPSite site = new SPSite("http://amitkumarmca04.blogspot.com/")) { using (SPWeb web = site.RootWeb) { PublishingWeb publishingWeb = Publishing

Accessing SharePoint Quick Launch menu (SPNavigation.QuickLaunch) using C#:

Accessing SharePoint Quick Launch menu (SPNavigation.QuickLaunch) using C#: With the help of SPNavigation, we will be able to access the Quick Launch menu of SharePoint site. Sometimes we need to show/hide Quick Launch menu item, so with the help of SPNavigation. QuickLaunch, we can loop through Quick Launch menu item. In this example we will access Quick Launch menu: using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office.Server.UserProfiles; using Microsoft.SharePoint; using System.Web; using Microsoft.SharePoint.Navigation; namespace GetQuickLaunch { class Program { static void Main(string[] args) { using (SPSite site = new SPSite("http://amitkumarmca04.blogspot.com/")) { using (SPWeb web = site.OpenWeb()) { SPNavigationNodeCollection qlNodes = web.Navigation.Quic

SharePoint web parts properties validation

SharePoint web parts properties validation Sometimes, in a custom web part we define the custom properties. It’s very difficult to validate properties every time by opening the web part in edit mode. So we needed to include validations on it so that whenever the user clicked OK or Apply the error message should be shown so that the correct input should be given. Solution 1 : Earlier definition of the Property private string _amitKumar=String.Empty; public string AmitKumar { get {return _amitKumar;} set {_amitKumar = value;} } Updated web part property definition, private string _amitKumar =String.Empty; public string AmitKumar { get {return _amitKumar;} set { If(String.IsNullOrEmpty(value) { throw new Exception (“Value is required”); } else _amitKumar =value; } } The above approach works perfectly fine and will not let you close the properties pane until you provide the value in the _amitKumar field, you will keep g

Amit Kumar awarded “Microsoft Community Contributor Award 2011”

Image
Amit Kumar awarded “Microsoft Community Contributor Award 2011”: I’m very pleased and honored to share this with all of you that my community contributions have been recognized by Microsoft. I have received the Microsoft Community Contributor Award for year 2011. This is really great and I would like to thank Microsoft for honoring me with such an award!

How to convert absolute url to relative url

How to convert absolute url to relative url: URL: URL is just a fancy name for "address". You use a "url" to give the address to a link or image. Absolute url: An url that is ABSOLUTE shows the complete address. In other words, there is no confusion about where this item is located, as the ABSOLUTE URL gives the entire path to that file. http://amitkumarmca04.blogspot.com/2011/02/get-list-data-using-sharepoint-object.html is an example of an ABSOLUTE url. Relative url: A url that is RELATIVE only shows a partial address - like /2011/02/get-list-data-using-sharepoint-object.html - and the success or failure of finding the file is contingent on certain conditions being met - which means the outcome can and will vary, depending largely how the directories within your website are structured. Problem: After restoring the site from development environment to staging environment. If some document library having metadata like “ListURL”. This metadata contains url in the

Add password reset page in Form Based Authentication MOSS 2007 site

Image
Add password reset page in Form Based Authentication MOSS 2007 site: Overview: This article explains how to add a reset password page in Form Based Authentication enable SharePoint 2007 (MOSS) site, so the user can reset his/her password. We will add this page in standard menu. Problem: When you enable forms authentication on SharePoint 2007 (MOSS), it means that users credentials are stored in membership database like ASP.NET database. In Form Based Authentication site, if we want to reset password then reset password page should be accessible to anonymous user also. Solution: We are going to add new feature (ResetPasswordPage feature) in the standard user menu: 1. Write code .cs file(c# file), In this class, we will inherit the class Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase For example: public class ExtranetPasswordReset_Test : Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase 2. Creating ExtranetPasswordReset_Test.aspx 3. Creating ResetPasswordPage featur

How to deploy DLL’s into GAC using batch (.bat) file

How to deploy DLL’s into GAC using batch (.bat) file: Global Assembly Cache Tool (Gacutil.exe): The Global Assembly Cache tool allows you to view and manipulate the contents of the global assembly cache and download cache. gacutil [options] [assemblyName assemblyPath assemblyListFile] The Gacutil is a tool used by developers to install versioned assemblies into the system Global Assembly Cache (GAC) to become part of the assemblies that are available for all applications at runtime. Parameter: assemblyName: The name of an assembly. You can supply either a partially specified assembly name such as myAssembly or a fully specified assembly name such as myAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0038abc9deabfle5. assemblyPath: The name of a file that contains an assembly manifest. assemblyListFile: The path to an ANSI text file that lists assemblies to install or uninstall. To use a text file to install assemblies, specify the path to each assembly on a separate line in

Default/Integrated role in SharePoint 2007

Default/Integrated role in SharePoint 2007: A role consists of two parts: 1. Role definition 2. Role assignment. The role definition , or permission level, is the list of rights associated with the role. A right is a uniquely controllable action within a SharePoint Web site. For example, a user with the Read role can browse pages in the Web site and view items in lists. Unlike in Windows SharePoint Services 2.0, in Windows SharePoint Services 3.0 user permissions are never managed directly using rights. All user and group permissions are managed through roles. A role definition is a collection of rights bound to a specific object. Role definitions are scoped to the Web site (for example, Full Control, Read, Contribute, Design, or Limited Access) and mean the same thing everywhere within the Web site, but their meanings can differ between sites within the same site collection. Role definitions can also be inherited from the parent Web site, just as permissions. The role assignment is

Encrypting Web.Config

Encrypting Web.Config using RSAProtectedConfigurationProvider in SharePoint Overview: One of the most common uses of the protected configuration is to encrypt connection strings in web.confg (that's one of the reasons for creating a separate tag for connection strings instead of adding it in appSettings tag). Adding this connection string as plain text is not the best practice for sharepoint web application security and this might cause serious hacking problems. Sharepoint also support for encrypting and decrypting configuration sections in web.config file. In this article, we will explore how to encrypt and decrypt sections of the web.config. We can encrypt the configuration sections by using two built-in providers: DPAPI (Windows Data Protection API) Provider or the RSA provider. The RSA provider (default) uses an RSA key which holds public and private keys, where as the DPAPI provider uses built-in machine-specific key. Let us explore the steps required to encrypt the sections u

Get list data using SharePoint Object Model

Get list data using SharePoint Object Model: This article explains how you can use the SharePoint Object Model(MOSS 2007) classes like SPSite and SPWeb in C# or Visual Basic code to fetch data from a custom SharePoint list. This article explains how you can use the SharePoint Object Model(MOSS 2007) classes like SPSite and SPWeb in C# or Visual Basic code to fetch data from a custom SharePoint list. Problem: You want to get data on the basis of url (including siteurl+listname) from the custom SharePoint list. Resolution: In this scenario, we can use SharePoint Object Model classes to access data from custom SharePoint list. public static bool CheckListExists(string listName, SPWeb web,ref SPList list) { try { //---Check list exist or not if (web.Lists[listName]!=null) { list = web.Lists[listName]; return true; } return false; } catch (ArgumentE

Customizing Styles of Summary Links Web Parts

Image
Customizing Styles of Summary Links Web Parts: The Summary Link field control present authored links on your page. You can base these links on a set of styles available to the Web site. You can also style the items and group headers in these Web Parts so they use a set of available styles to render. Microsoft Office SharePoint Server 2007 uses XSL style sheets to present these Web Parts. You can customize and extend styles to match the color and branding of your Web site. The following table shows the mapping of XSL style sheet files and the corresponding Web Parts. XSL Style Sheet Purpose Corresponding Web Part ContentQueryMain.xsl "Application" XSL style sheet Content Query Header.xsl Group headers for Content Query and Summary Links, title headers for Table of Contents Content Query, Summary Links, Table of Contents ItemStyle.xsl Content Query and Summary