Friday, 6 July 2012

Create list and list column programatically


            SPSite mySite = (SPSite)properties.Feature.Parent;
            SPWeb myWeb = mySite.OpenWeb();
            myWeb.AllowUnsafeUpdates = true;

           
            myWeb.Lists.Add("NewsAndEvents", "The information about News and Archieves", SPListTemplateType.GenericList);
            SPList myList = myWeb.Lists["NewsAndEvents"];
            SPView defaultView = myList.DefaultView;

            SPFieldDateTime eventDate = (SPFieldDateTime)myList.Fields[myList.Fields.Add("EventDate", SPFieldType.DateTime, true)];
            eventDate.Description = "The Date of the Event";
            eventDate.Update();
            defaultView.ViewFields.Add(eventDate);

            SPFieldMultiLineText eventDescription = (SPFieldMultiLineText)myList.Fields[myList.Fields.Add("EventDescription", SPFieldType.Note, true)];
            eventDescription.Description = "Description about the event";
            eventDescription.RichText = true;
            eventDescription.RichTextMode = SPRichTextMode.FullHtml;
            eventDescription.Update();
            defaultView.ViewFields.Add(eventDescription);

            SPFieldUrl pictureURL = (SPFieldUrl)myList.Fields[myList.Fields.Add("Picture", SPFieldType.URL, false)];
            pictureURL.Description = "The URL address of the picture";
            pictureURL.Update();
            myList.Update();
            defaultView.ViewFields.Add(pictureURL);
            defaultView.Update();
            myList.Update();
            myWeb.AllowUnsafeUpdates = false;




Tuesday, 3 July 2012

SharePoint Feature Clean up tool (feature manager) link

SharePoint feature is an amazing tool.  Which in used to manager the feature in our SharePoint.
Here the link to download it
http://featureadmin.codeplex.com/

Happy Coding :))

Thursday, 28 June 2012

Create custom master page in SharePoint 2007 using Visual Studio

  1. Open Visual Studio 2010 before that please install wspbuilder extension
  2. File->New->Project Select WSPBuilder Project under the WSPBuilder Category
  3. Add new item to the project Select Blank Feature with site scope in the WSPBuilder Category.
  4. Please add the folders and masterpage in the following strucure. 
  • Features
    • SugunthanMasterPageFeature(your feature folder)
      • _catalogs (folder)
        • masterpage(folder)
          • SugunthanMaster.Master(Your master page file)

      5. Remove the Code behind and designer cs files.
      6. Open the element files and change the code like following


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="SugunthanMasterPageFeature" Url="_catalogs/masterpage" Path="_catalogs/masterpage" RootWebOnly="TRUE">
    <File Url="SugunthanMaster.Master" Path="SugunthanMaster.Master" Type="GhostableInLibrary">
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;"></Property>
      <Property Name="MasterPageDescription" Value="SugunthanMaster.Master" />
    </File>
  </Module>
</Elements>

Note Module Name is your Feature Name.

     7. Open the master page remove all coding
     8. Open any default master page in sharepoint designer and copy the code then paste to your master page
      9. Do the changes and add style what you need.
    10. Compile the code.
    11.  Add and deploy the solution
    12.  Open the Particular website and activate the feature in the site feature collection
    13.  Go to the settings in the look and feel change the master page as yours one.

Happy Coding:)

Wednesday, 20 June 2012

How to read the contact list of my exchange server mail account

This code read the contact list of my exchange 2007 server mail account using c#

private static void ListContacts(ExchangeService svc) {
    foreach (var v in svc.FindItems(WellKnownFolderName.Contacts,
                                    new ItemView(20))) {
        Contact contact = v as Contact;
        ContactGroup contactGroup = v as ContactGroup;

        //v.Load(); // Turns out you don't need to load for basic props.
        if (contact != null) {
            Console.WriteLine("Contact: {0} <{1}>",
                contact.DisplayName,
                contact.EmailAddresses[EmailAddressKey.EmailAddress1]);
        } else if (contactGroup != null) {
            Console.WriteLine("Contact Group: {0}", contactGroup.DisplayName);
            switch (svc.RequestedServerVersion) {
                case ExchangeVersion.Exchange2007_SP1:
                    ExpandGroupResults groupResults
                        = svc.ExpandGroup((contactGroup.Id));
                    foreach (var member in groupResults) {
                        Console.WriteLine("+ {0} <{1}>",
                            member.Name, member.Address);
                    }
                    break;
                case ExchangeVersion.Exchange2010:
                    foreach (GroupMember member in contactGroup.Members) {
                        Console.WriteLine("+ {0} <{1}>",
                        member.AddressInformation.Name,
                        member.AddressInformation.Address);
                    }
                    break;
                default:
                    Console.WriteLine(
                        "** Unknown Server Version: {0}",
                        svc.RequestedServerVersion);
                    break;
            }
        } else {
            Console.WriteLine("Unknown contact type: {0} - {1}",
                contact.GetType(), v.Subject);
        }
    }
}
 
Note:  Please install ews api and add the following references
using Microsoft.Exchange.WebServices.Data;
using System.Collections.ObjectModel;
 
Webservices available in the folder "C:\Program Files\Microsoft\Exchange\Web Services\1.2" 
before check this program .
 
Happy Coding :) 

Wednesday, 23 May 2012

Types of Deployment in SharePoint 2007

Who Needs Deployment?

Regarding the development environment, there are two types of SharePoint projects:
  • Single environment projects, where everything is configured and developed directly in the production environment;
  • Multiple environment projects, where all the development and configuration is done in a development environment, then possibly deployed to a testing environment, and finally deployed to the production environment.
Additionally, you can have two types of farms, in a SharePoint installment:
  • Single server farm, when there is only one SharePoint Server in the farm (although there can be additional SQL Servers);
  • Multiple server farm, when there are several SharePoint Servers, possibly with different server roles, in the farm.
For Single Server – Single Environment projects, which are the least common type, the developers don't really need to be concerned about deployment since everything is done on the same server. But for the other types of projects (Single Server – Multiple Environment, Multiple ServerSingle Environment and Multiple Server Multiple Environment) developers will need to deploy their work to the servers.

What Does Deployment Mean, in a SharePoint Sense?

In SharePoint, deployment means the necessary actions to install your software solution in a SharePoint environment, whether that solution consists of web parts, custom web controls, event handlers, custom web pages, or just master pages.
So, imagine you have created site columns and content types directly on the SharePoint UI, customized some master pages using SharePoint Designer and installed a few custom web parts on your Development Environment, and now you need to deploy this to the Testing Environment (and later on, to the Production Environment). You can choose from a few different deployment methods:
  • Stone Age Deployment. You do it all over again in the Testing Environment, and later you will repeat the procedure in the Production Environment. It's not hard to figure out this is a bad practice: probably you won't be able to repeat the tasks in the exact same order as you did before, and that might result in errors or in a Testing Environment that is not a replica of the Development Environment. Also, that means the developers must have administration access in all the environments, which is not always the case.
  • Backup/Restore Deployment. You perform a farm backup on the Development Environment and restore it in the Testing Environment. Although commonly used, it's not the best practice either: you must make sure all the assemblies, web.config modifications, and file system changes are present in the destination environment before you restore the backup. Also, you might have some problems if the environments are not in the same windows domain.
  • Content Deployment. You use SharePoint's content deployment paths and jobs. That can be a good solution, but it has some limitations: unless you are deploying a whole site collection, you'll need to make sure all the assemblies, web.config modifications, and file system changes are present in the destination environment before you restore the backup. Content deployment is targeted at "contents" and not at "structure", although some of the SharePoint structures are migrated with the contents. Also, both environments must be connected for automatic content deployment to work. You have the option to export a site collection to a .CAB file and import it in the destination environment using STSADM commands, but the same limitations apply.
  • Solution Deployment. You build SharePoint Features for all the objects you developed and pack them in one or more SharePoint Solutions. This is the recommended approach for structure deployment, since it allows for multiple server farm deployment, allows the deployment of assemblies, web.config modifications, files in file system folders as well as all SharePoint objects.

Tuesday, 22 May 2012

How to view all user of a active directory group


public static DataSet GetUsersForGroup(string GroupName)
{
DataSet dsUser = new DataSet();
DirectoryEntry de = GetDirectoryObject();

//create instance fo the direcory searcher
DirectorySearcher deSearch = new DirectorySearcher();

//set the search filter
deSearch.SearchRoot =de;
//deSearch.PropertiesToLoad.Add("cn");
deSearch.Filter = "(&(objectClass=group)(cn=" + GroupName +"))";

//get the group result
SearchResult results= deSearch.FindOne();

//Create a new table object within the dataset
DataTable tbUser = dsUser.Tables.Add("Users");
tbUser.Columns.Add("UserName");
tbUser.Columns.Add("DisplayName");
tbUser.Columns.Add("EMailAddress");

//Create default row
DataRow rwDefaultUser = tbUser.NewRow();
rwDefaultUser ["UserName"]= "0";
rwDefaultUser ["DisplayName"]="(Not Specified)";
rwDefaultUser ["EMailAddress"]="(Not Specified)";
tbUser.Rows.Add(rwDefaultUser);

//if the group is valid, then continue, otherwise return a blank dataset
if(results !=null)
{
//create a link to the group object, so we can get the list of members
//within the group
DirectoryEntry deGroup= new DirectoryEntry(results.Path,ADAdminUser,ADAdminPassword,AuthenticationTypes.Secure);
//assign a property collection
System.DirectoryServices.PropertyCollection pcoll = deGroup.Properties;
int n = pcoll["member"].Count;

//if there are members fo the group, then get the details and assign to the table
for (int l = 0; l < n ; l++)
{
//create a link to the user object sot hat the FirstName, LastName and SUername can be gotten
DirectoryEntry deUser= new DirectoryEntry(ADFullPath + "/" +pcoll["member"][l].ToString(),ADAdminUser,ADAdminPassword,AuthenticationTypes.Secure);

//set a new empty row
DataRow rwUser = tbUser.NewRow();

//populate the column
rwUser["UserName"]= GetProperty(deUser,"cn");
rwUser["DisplayName"]= GetProperty(deUser,"givenName") + " " + GetProperty(deUser,"sn");
rwUser["EMailAddress"]= GetProperty(deUser,"mail");
//append the row to the table of the dataset
tbUser.Rows.Add(rwUser);

//close the directory entry object
deUser.Close();

}
de.Close();
deGroup.Close();
}

return dsUser;
}

Friday, 18 May 2012

jQuery font issue in SharePoint

I tried to added jquery datepicker in the custom webpart finally added the datepicker.  After that I noticed in my SharePoint 2007 site menu style totally changed the font size of the menu became tiny.

The way to fix the problem is

1. Open the jquery style sheet demos.css
2. Remove the style
 table
 {
    font-size: 1em;
  }

now it is working fine.

Happy Coding :)