Posts

Showing posts from October, 2012

SharePoint 2010 root directory

In this blog we will discuss about SharePoint 2010 root directory. SharePoint stores some template files in a special directory on the local file system of each front-end Web server, which is know as SharePoint root directory. It is also know as 14 hive directory in SharePoint 2010 and 12 hive directory in MOSS 2007. If SharePoint is installed in C drive then it usually will be in the below location: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14 For SharePoint foundation, it contains set of images, templates, features, and pages. But if you install SharePoint server then it contains images, templates, features, and pages and some template files which provides additional functionality apart from SharePoint Foundation. Below are some sub directory and the type of template files it contains: /ISAPI: This directory contains all the Web Services (.svc, .ashx, .asmx) as well as the required dlls for SharePoint like Microsoft.SharePoint

NullReferenceException on SPWorkflowTask.AlterTask ()

In a custom task edit form for a custom content type, the following code is used to update the task item: Hashtable taskHash = new Hashtable(); taskHash["Status"] = "Approved"; taskHash["PercentComplete"] = "1"; SPWorkflowTask.AlterTask(this._taskItem, taskHash, true); This works great most of the time, however, if the custom content type defines no fieldrefs, or more specifically, the content type XML does not have the node, as could be the case if only a custom form is included in the custom content type, the following exception would be thrown on the AlterTask line: System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." Source="Microsoft.SharePoint" because there is no columns in your task list ( you should not refer any fields in your content type). So To fix this error, make sure that the node is in the content type definition XML, even whe

Create Top Navigation for SharePoint Custom Master Page

As the part of customization masterpage sometimes you need to add top level navigation with specified sites. Here is the coolest way to achieve this using aspx menu bar control. Create a visual webpart in visual studio 2010 and add aspx menu control on the user control. <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" CssClass="xxxxx"><asp:Menu> // Apply styles as your wish Take a custom list and create column [ ex:MenuUrl]   that using for url of the top navigations[Ex: https://xxxxxxx/home.aspx]. And add this list content to aspx menu on page load event as shown in below code. protected void Page_Load(object sender, EventArgs e) {   if (!IsPostBack)   { SPWeb web = SPContext.Current.Web; SPList list = web.Lists["ListMenu"]; SPListItemCollection items = list.Items; // get the list item for menu control //Title is the display name and MenuUrl refers the navigation url.

Send Mails in SharePoint Event Receiver

After I getting the user, email id from item( described in Previous Post) . Now I need to send mail to the user, I tried lot of ways to send mails and finally I realise that below code is best for my scenario to send mails. SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = properties.Web.Site.WebApplication.OutboundMailServiceInstance.Server.Address; MailMessage mailMessage = new MailMessage(MailFrom, mailTo); mailMessage.Subject = MailSubject; mailMessage.Body = MailBody; mailMessage.IsBodyHtml = true; smtpClient.Send(mailMessage); here smtpClient.Host is getting the local mail server address and we include from, to and subject, body in MailMessage and finaly send the message using smtpClient.Send(mailMessage), and don’t forgot to include try catch blocks. Good luck.

Get user from Person or Group Field in Sharepoint List

There is a situation I need to add item to list and send mail to person who is on the same item xxxx field. Here xxxx is the person or group field and I set show field as “Name” [!i.e Display Name]   in list settings .   If we try to get values using properties.listItem[xxxx] it returns a junk characters with DisplayName and again we need remove the junk characters and query to user profiles to get the mail id. Sometimes [user profile not synchronized well] it didn’t query to get value based on “DisplayName”. So this situation I try to get the actual user of the filed instead of DisplayName. then i try the following code in event receiver.  SPFieldUser userField = (SPFieldUser)properties.OpenWeb().Lists[listName].Fields.GetField("xxxx"); SPFieldUserValue fieldValue=(SPFieldUserValue)userField.GetFieldValue(properties.ListItem["xxxx"].ToString()); accountName = fieldValue.User.LoginName; here fieldValue.User is SPUser,   the SPUser.logingName ret