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..!

Thursday, February 25, 2010

Publshing info path form to share point library.


In this article we will see how to create and publish the Info Path Form into Form Services in MOSS 2007. It has following steps

  1. How to design the Form using Info Path 2007
  2. How to check the Browser compatibility for the Form
  3. How to deploy it in the Form Server

Design the Form using Info Path 2007










Use the option Design checker to check for any errors are there

Check the Option.’ Design a Form template that can be opened in a browser or Info Path'.

If you want to verify your template

After enabling the Browser enabled Form, check the error in Design the Checker Tab since we have some unsupported controls for browser enabled form such as combo box, rich text controls.










From the File Menu, choose Publish.

Select the option 'To a SharePoint server with or without InfoPath Forms Services'










Enter the URL of the Web Application.












Check the Browser compatibility for the Form

Select the Document Library and verify that the option 'Enable this form to be filled out by using browser' is checked.










Deploy it in the Form Server If you want to create a new Document Library, choose Create a new Document Library or else you can update the Form template in an existing Document Library.Enter the Name of your Document Library.










Select the fields to be published in the Form Library.










Click on Publish to publish the form to document library










This is a confirmation screen for the template published successfully in the Form Library.


Monday, February 22, 2010

Creating Custom properties for web parts in Web user Control for smart part templates

Creating Custom properties for web parts in Web user Control for smart part templates

Hi friends ,
As I have gone through lot of search for creating custom properties for web user control which is used in smart part template as a custom web part but unfortunately there is no such help I found. So here I am giving some of the tips by which any one can under stand the implementation of custom properties in web user control.
I am considering that you know how to use smart part template and point to the web user control

Steps for creating properties.

1. Create the local variable required for custom properties

public partial class UCContactList : System.Web.UI.UserControl
{
#region For local varibles
//for names
///



/// Used for storing first contact info.
///

private string firstContact = string.Empty;
#endregion

2.Create the custom property with required attributes.

//properties for name
[Browsable(true), //Display the property in property pane
Category("Coolsoft Details"), //Create a Customer Details category in property pane
DefaultValue(false), //Assign a default value
WebPartStorage(Storage.Personal),//Make available in both personal and shared mode
FriendlyName(" First Contact"), //The caption display in property pane
Description(" First Contact Name")]//The tool tip
public string FirstConatactName
{
get
{
return firstContact;
}
set
{
firstContact = value;
}
}


3. Use the custom property in page load method for assigning any control.. in my case I done like this..

protected void Page_Load(object sender, EventArgs e)
{

//for first contact
this.hlFirstContact.Text = this.FirstConatactName
}

that's very easy..