Monday, July 12, 2010

SharePoint Hierarchy

http://suryakantblog.blogspot.in/



SharePoint Hierarchy is one of the important concept that every share point developer must know. I am giving below some explanation about it for enhancement of knowledge The figure given at the left side gives better idea to understand the hierarchy in share point At the top level of the hierarchy is Server Farm. This is physical server which consist of share point installation. It may contain more than one server which we can defined at the time of installation. Next to the server farm is Web Application which is created on server using CA site. This is where all site collations get created and we can have mapping as well as choice of application pool at this level only. In Web Application we can create number of the site collections we can set the top level site and number of subsides below it. Sites or Website is created under the site collection. We can create number of sites in site collection as per the requirements. Sites are the actual place where we have physical interface of all elements like list library etc. List Library are the lowest level element in share point hierarchy. Those are created under only site. It’s very important understand this hierarchy, because We can’t create any element by crossing these.IE. site can only be created under only site collection and not under WA or server Farm.

Friday, May 21, 2010

Receiving email to sharepoint list

Receiving an email to share point list is quite hard as compare to sending mail from list. This is one of the complicated thing on which I have worked in last few days. So here I am giving small solution for the problems that people are facing for this task, which I have seen on net while doing some goggling during task.The problems are like this type that list is enabled for receiving the mail but columns name not get updated ,how to debug the library..etc. Here i am giving some stuff may be people will get help from it.
I will explain as steps wise..
step1: For receiving mail to share point list you should have SMTP server install on your computer with its domain name properly configured
Step2: In Central Administration site in Operation section incoming mail settings needs to be done Here you will have to mention the name of domain server to which mail will be sent.
Step3: After done with all this the important factor is you will have to write the Email Receiver Handler library and register it to the specified share-point list. This event will fire whenever it receives mail and process as per the business logic you written in it.The DLL must need to add at GAC.
Step4: After registering the handler to list go to list settings.In communication tab there must be on link called In Coming Email settings. Click it and give the email address for this list.

Step5: Once done with above steps shoot a mail to specified library and check it out in C:\inetput\mailroot\drop folder . The mail comes first at here then Share point timer service is checking after one min duration for this folder.It transfer it to given list address.

Now I will give some code stuff for writing handler

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.EmailIntegration;
using System.Text.RegularExpressions;

namespace EmailReceiverHandlers
{
///
/// This class adds custom data from email to list
///

class MailEventHandler : SPEmailEventReceiver
{
SPListItem item;
public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
{
try
{
list.ParentWeb.AllowUnsafeUpdates = true;
list.EnableAssignToEmail = true;
list.EnableAttachments = true;
item = list.Items.Add();
item["Title"] = emailMessage.Headers["subject"].ToString();
item.Update();
}
catch (Exception ex)
{
// EventLog.WriteEntry(sSource, "Error occured in EmailReceived method of class
MailEventHandler of type " + ex.Message, EventLogEntryType.Error);
}


}
}

Use OWSTIMER process from attach process for debugging the code.
Thanks..!

Wednesday, May 12, 2010

Error:Column name that you entered is already in use or reserved

Hi Friends
Few days back while working with list I got one problem I solved that after some goggling may be some you will help it out.
I want to create one custom column for my custom list but while creating it from list setings it was giving following error.











After some search I found that if you have created same column name with some list and if its added in site column gallery it goes there.If you delete that list all column names related with that list get deleted but it keep that column name reference in some hidden group which can not be seen through share point UI.

To solve this problem you have just execute the following script in address bar of that list page
as below
The Script is...
javascript:g_FieldName={};alert('Successfully cleared forbidden columns');













The above script clears all the values in the forbidden column collection array and gives you a confirmation. Now try creating the column now.You should be able to.

Friday, April 9, 2010

Creating custom properties in visual web part 2010



Visual webpart is one of best feature provided in Sharepoint 2010.This is the capability to create Webparts using a visual interface in Sharepoint 2010 so it’s called as Visual WebParts. it’s become very easy and fast to create webpart as well as deploy webpart to sharepoint server. Bringing visual webpart in visual studio 2010 microsoft had made it less effotable task. But there are some complicated things still developers need to know and one of that is creating custom properties. Few days back I worked on it for one the customer requirement. I think this could be very useful blog for those who are working on custom web part development using visual studio 2010.
When create new visual web part VS creates following files structure for a new visual web part

















It y creates the web part class and calls the user control by using page.LoadControl method. When we deploy the web part it copies the user control to the Control template folder under 14 hives and defies the same path in web part class.
The main thing we discus here is custom properties. The custom properties are written like this in user control class.
//properties for Title
[System.Web.UI.WebControls.WebParts.WebBrowsable(true),
System.Web.UI.WebControls.WebParts.WebDisplayName("WebPart Title"),
System.Web.UI.WebControls.WebParts.WebDescription(""),
System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
System.ComponentModel.Category("Settings"),
System.ComponentModel.DefaultValue("")
]

public string WebpartTitle
{
get
{
return title;
}
set
{
title = value;
}
}
//propertiesfor Group Name
[System.Web.UI.WebControls.WebParts.WebBrowsable(true),
System.Web.UI.WebControls.WebParts.WebDisplayName("Group Name"),
System.Web.UI.WebControls.WebParts.WebDescription(""),
System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
System.ComponentModel.Category("Settings"),
System.ComponentModel.DefaultValue("")
]
public string GroupName
{
get
{
return groupName;
}
set
{
groupName = value;
}
}

The same above mentioned code we need to write in web part class. In create child controls class we need to access the properties like this way
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/SiteUsersWP/VisualWebPart1/VisualWebPart1UserControl.ascx";
protected override void CreateChildControls()
{
usercontrol = (VisualWebPart1UserControl)this.Page.LoadControl(_ascxPath);
usercontrol.WebpartTitle = this.WebpartTitle;
usercontrol.GroupName = this.GroupName;
Controls.Add(usercontrol);
base.CreateChildControls();

}

The custom properties we write goes under settings section when we edit web part in user interface.

Tuesday, March 23, 2010

Customizing the Application .master page.


When we have requirements of customizing the site master page it can be done easily by editing master page using SharePoint designer as per our requirement. When we set the customized master page to a site, the site pages render with new master page but application or system pages render with Applicaton.master page. In this situation the changes we have done with custom master page mismatches with application .master page.

To bring uniformity to over all pages in site we have to modify the application master page as like custom master page.

It can be done with following way.

Step 1. Create the custom module for redirecting the control to custom Application master page from default Application. Master page at runtime.

  1. Open Visual Studio
  2. Create a New Project
  3. Choose a Class Library project (for this walkthrough I am referring to a C# class library, but the steps are the same for other types)
  4. Call it MyHttpModule
  5. Rename Class1 to MyCustomHttpModule
  6. Change the code in MyCustomHttpModule to look like this:

using System;
using System.Web;
using System.Web.UI;
using System.IO;

namespace MyHttpModule
{
public class MyCustomHttpModule: IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.PreInit += new EventHandler(page_PreInit);
}
}

void page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
if (page != null)
{
if (page.MasterPageFile != null)
{
if (page.MasterPageFile.Contains(“application.master”))
{
page.MasterPageFile = “/_layouts/MasterPages/Custom.master”;
}
}
}
}

public void Dispose()
{
}
}
}

  1. Sign the project – this is needed to add the dll to the GAC
    • Right click on the MyHttpModule project and go to the properties
    • Go to the “Signing” link on the right side
    • Click the checkbox to “Sign the assembly”
    • In the “Choose a strong name key file” dropdown, choose “
    • Enter a “Key file name”.
    • Uncheck the “Protect my key with a password” checkbox
    • Click “Ok”
  2. Build the project
  3. Place the dll in the GAC
    • If you built in Debug mode then the dll will be at: /bin/debug/MyHttpModule.dll
    • Drag the dll (do not copy and paste) into the GAC: C:\Windows\assembly

Step 2 – Register the module

  1. Find the web config for your site. If you did not specify a path when you created your web application then this is located at C:\Inetpub\wwroot\wss\VirtualDirectories\. If you did specify a different path and don’t remember where it is, the best way to figure it out is to go into IIS, find your website, go to the properties, click on the “Home Directory” tab. Your path will be in the “Local path” text box.
  2. Add this into the web.config file within the “httpModules” section

/>

Note a few things:

  • Type=,
  • PublicKeyToken – this can be found by going to the dll in the GAC (C:\Windows\assmebly), then right click and look at the properties of the dll.

Step 3 – Put a custom master page in the layouts folder

In Step 1 we told the code to look for the master page in /_layouts/MasterPages/Custom.master. Thus, we need to actually have a master page there.

  1. Copy the application.master from %Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
  2. Create a new folder called “MasterPages” under %Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
  3. Paste the application.master page in the newly created MasterPages folder
  4. Rename the application.master page in the Master Pages folder to Custom.master

Step 4 – Make changes to the Custom.master

Now that you have built an HttpModule to redirect to the Custom. Master page you can customize your Custom. master page however you want. But, you still have to be careful about keeping the content place holders around per the articles I have been writing in this series.

Thursday, March 11, 2010

Deploying content from development server to Production server using SPContentDeployment wizard (2.7) beta

Hi friends,
This is one more blog I am giving here for easy and quick deployment of content in SharePoint from development server to production server. Use the following steps for proper import and export of content.
Steps for exporting the content
Open the SharePoint content deployment wizard
















Supply the details the site you wish to use
















Add the export list
















It displays the selected site in selected items like this(see the red border text)















Set the export option( path for storing content file and name of .cmp file)
















Click on finish to complete the task.














After successful completion it will display the message like this















Click OK and exit the window. So Export operation is now complete. The Next step is Import this content on production server.




Steps for importing the content on production server.

For importing the content on production server we have to create the blank site collection on production server. After creating the blank site collection we can import the content by using the SPContentDeployment wizard.
Start the SPContentDeployment wizard and select the Import option then provide required details of site. Click next..















Select the .cmp file for import which we have created using export operation. Check Retain object IDs and location check box.















Click on finish to complete the operation.















Thats..sit done..!