SharePoint’s type of List & its Item’s Field

Calendar List

Field Name Type
Location String
Start Time DateTime
End Time DateTime
Description String
Title String
Category String
fAllDayEvent Boolean
   
   

Contact List

Field Name Type
Title String
FirstName String
FullName String
Email String
Company String
JobTitle String
WorkPhone String
HomePhone String
CellPhone String
WorkFax String
WorkAddress String
WorkCity String
WorkState String
WorkZip String
WorkCountry String
WebPage String
Comments String

Announcement List

Field Name Type
Title String
Body String
Expires DateTime

Disscussion List

Field Name Type
Title String
Body String

Task List

Field Name Type
Title String
Status String
PercentComplete String
Priority String
Body String
StartDate DateTime
DueDate DateTime
AssignedTo user

Issue List

Field Name Type
Title String
Status String
Comments String
Priority String
Description String
DueDate DateTime

Link List

Field Name Type
URL SPFieldUrlValue
Notes String

Programmatically add an item/Contact to a SharePoint 2010 Contact List

Here,in this post I am going to describes how we can programmatically add an contact to the SharePoint 2010.

We go here step by steps.So.let’s begin.

(1) Creating the Contact List.

//Get  the Site under which you want to create Contacts.

SPSite site = new SPSite(http://localhost);
SPWeb web = site.AllWebs[0];

//Give the Type of List you want to create,in Our case it’s noting but Contacts.
SPList list = web.Lists["Contacts"];

Now,Up to this we has the instance of Contact list.

(2)Adding Contact In to Contact list.

To Add/Create the Contacts we need to update following field.

Field Name Type
Title String
FirstName String
FullName String
Email String
Company String
JobTitle String
WorkPhone String
HomePhone String
CellPhone String
WorkFax String
WorkAddress String
WorkCity String
WorkState String
WorkZip String
WorkCountry String
WebPage String
Comments String

//Adding event into list
  SPListItem contact = list.Items.Add();

contact["Title"] = “Rajput”;

contact["FirstName"] = “Chirag”;

contact["FullName"] = “Rajput Chirag”;

contact["Email"] =  “Chirag@test.com”;

contact["Company"] = “My Company”;

contact["JobTitle"] = “Software Eng.;

contact["WorkPhone"] = “0303- 1233344” ;

contact["HomePhone"] = “2121-323232”;

contact["CellPhone"] = “+1213232323”;

contact["WorkFax"] = “122132-3232”

contact["WorkAddress"] = “ddadadada”;

contact["WorkCity"] = “Bangalore”;

contact["WorkState"] = “Karnataka”;

contact["WorkZip"] = “1212-32”;

contact["WorkCountry"] = workcountry" ;

contact["WebPage"] = “http://Mylog.com”;

contact["Comments"] = “MyComments”;

contact.Update();

Your,final code will look like this.

//Get  the Site under which you want to create Contacts.

SPSite site = new SPSite(http://localhost);
SPWeb web = site.AllWebs[0];

//Give the Type of List you want to create,in Our case it’s noting but Contacts.
SPList list = web.Lists["Contacts"];

//Adding Contact into list
  SPListItem contact = list.Items.Add();

contact["Title"] = “Rajput”;

contact["FirstName"] = “Chirag”;

contact["FullName"] = “Rajput Chirag”;

contact["Email"] =  “Chirag@test.com”;

contact["Company"] = “My Company”;

contact["JobTitle"] = “Software Eng.;

contact["WorkPhone"] = “0303- 1233344” ;

contact["HomePhone"] = “2121-323232”;

contact["CellPhone"] = “+1213232323”;

contact["WorkFax"] = “122132-3232”

contact["WorkAddress"] = “ddadadada”;

contact["WorkCity"] = “Bangalore”;

contact["WorkState"] = “Karnataka”;

contact["WorkZip"] = “1212-32”;

contact["WorkCountry"] = workcountry" ;

contact["WebPage"] = “http://Mylog.com”;

contact["Comments"] = “MyComments”;

contact.Update();

Thanks.

Programmatically add an item/event to a SharePoint 2010 calendar

Here,in this post I am going to describes how we can programmatically add an Event to the SharePoint 2010.

In SharePoint, Calendar is nothing but the one type of list.So as we are adding item in it,we can create the event for Calendar.

We go here step by steps.So.let’s begin.

(1) Creating the Calendar.

//Get  the Site under which you want to create Calendar.

SPSite site = new SPSite(http://localhost);
SPWeb web = site.AllWebs[0];

//Give the Type of List you want to create,in Our case it’s noting but Calendar.
SPList list = web.Lists["Calendar"];

Now,Up to this we has the instance of Calendar list.

(2)Adding Event In to Calendar.

To Add/Create the calendar we need to update following field.

Field Name    Type    
Location String      
Start Time DateTime      
End Time    DateTime 
Description    String      
Title    String      
Category    String    
fAllDayEvent    Boolean

 

//Adding event into list
  SPListItem newEvent = list.Items.Add();

newEvent["Location"] = “This is location”;

newEvent["Start Time"] = DateTime.Now;

newEvent["End Time"] = DateTime.Now.AddHours(1);

newEvent["Description"] = “Going for Meting”;

newEvent["Title"] = “New Meting”;

newEvent["fAllDayEvent"]  =  false;

newEvent["Category"] = “Meting”;
 

//Create Event in the sharpoint.        
newEvent.Update();

Your,final code will look like this.

//Get  the Site under which you want to create Calendar.

SPSite site = new SPSite(http://localhost);
SPWeb web = site.AllWebs[0];

//Give the Type of List you want to create,in Our case it’s noting but Calendar.
SPList list = web.Lists["Calendar"];

//Adding event into list
  SPListItem newEvent = list.Items.Add();

newEvent["Location"] = “This is location”;

newEvent["Start Time"] = DateTime.Now;

newEvent["End Time"] = DateTime.Now.AddHours(1);

newEvent["Description"] = “Going for Meting”;

newEvent["Title"] = “New Meting”;

newEvent["fAllDayEvent"]  =  false;

newEvent["Category"] = “Meting”;

//Create Event in the sharpoint.        
newEvent.Update();

Enjoy your Calendar Event.



    
     

           
        


 

Sending Mail in SharePoint

There is two way of sending the mail.
(1)using existing .net classes. (System.Net.Mail).
(2)using the SharePoint classes(Microsoft.SharePoint.Utilities).

The benefit of the second choice is you don’t need to store any other configuration for your SMTP server on your code.
The code will directly use the SharePoint configuration.

Configure the SharePoint for the sending the email

So.let’s first see,How we can configure the SharePoint for the sending the email.
To configure the SharePoint
(1)Open/Brows the  "SharePoint Central Administration Site".


(2) In Central Administration’s Menu click on the System Settings.

System settings

(3)Now,in right side click on the Configure outgoing e-mail settings under E-mail and Text Messages(SMS) section.

E-mail

(4)Now, in Outbound SMTP server give the name of the outgoing server address. e.g(smtp.provider.com)

(5)In From address filed give the from address( This can be overwrite by code,it’s ok if you keep this blank). and  click on ok.

Now,your SharePoint is configure to send the mail.

Sending the Mail

Below code will explain you how you can send the mail using SharePoint configuration.

This code is uses classes form the Microsoft.SharePoint.dll and Microsoft.SharePoint.Utilities.dll.

        public bool SendMail()
        {
                //Get Current website
                SPWeb web = SPContext.Current.Web;

               //Check emilServer is set
                bool isEmailServerSet = SPUtility.IsEmailServerSet(web);

                bool result = false;
                if (isEmailServerSet)
                {
                    //The email header
                    StringDictionary headers = new StringDictionary();
                    headers.Add("to","chiragbrajput@hotmail.com"));
                    headers.Add("cc", Chiragbrajput@hotmail.com);


                  //Change the from setting(optional)
                    headers.Add("from","hotmailAdmin@hotmail.com");
                    headers.Add("subject", "TestingEmail");
                    headers.Add("content-type", "text/html"); //This is the default type, so isn’t neccessary.

                    //The email body
                    string bodyText = "hello World";
                   //indicate mail send succefully or not.
                    result = SPUtility.SendEmail(web, headers, bodyText);
                }
    }