Friday, 22 November 2013

Deploying a custom master page in SharePoint 2010

  • I started out by creating an Empty SharePoint project. This can have any name you like and it can be both a farm and a sandboxed solution
  • Next add an new item to the project and choose a module
  • You can rename the module if you want to, I will leave the name at Module1
  • After the module is created it contains an elements.xml file and a sample.txt file. The sample.txt file can be renamed to sample.master.
Project structure
Project structure after adding a module and renaming the sample file to sample.master
I’m not a designer, so I wasn’t interested in creating a brilliant new design (good job, because I wouldn’t be able to do that!).
For the purpose of this example I just took the standard SharePoint 2010 master page contents.
  • Open up SharePoint Designer and open the site you are working on
  • Choose Master Pages on the left side
  • Open v4.master
Don’t let SharePoint fool you. There is a default.master, but this is the old SharePoint 2007 master page that is used if you perform a visual upgrade. When creating a site in SharePoint 2010 the master page that will be used by default is v4.master. I know it’s a bit confusing, but if you have been working with SharePoint for a while you won’t be surprised by this.
  • Copy the contents of v4.master and past them in your sample.master file in Visual Studio. Make the changes you want to.
  • Note how the elements.xml file has changed to reference the sample.master rather than the sample.txt
Contents of the elements.xml file 
The contents of the elements.xml file
  • Make sure the module is added to a feature in your project that is scoped at the site (= site collection) level
You could stop here and this solution will deploy your sample.master master page to the master page gallery of your site collection.
This will not apply the master page to the site collection when the feature gets activated though. It will only make it available for selection.
  • If you the master page to be applied when the feature gets activated you right click on the Feature1 and you add an event receiver. This will add a feature receiver file to the feature.
  • In this file we will add some code that will apply the sample.master master page when the feature gets activated and it will apply the v4.master when the feature gets deactivated.
 featurereceiver2  
Code used in the feature receiver
Now if you activate the feature the code in the feature receiver will run and will apply sample.master to the site. As you can see we change both the MasterUrl and the CustomMasterUrl. The MasterUrl is used on all pages that are not publishing pages. This means it is used on the pages in the sitepages library and on the pages in the _layouts directory like the settings page for instance. The CustomMasterUrl is only used on pages that are stored in the Pages library. This library is created when the SharePoint Server Publishing Infrastructure features is activated on the site collection and the SharePoint Server Publishing feature is activated on the site.
You can also use the SharePoint user interface to apply a new master page. The Site Master Page is the equivalent of the CustomMasterUrl and the System Master Page is what the object model calls the MasterUrl.

Changing the master page using the SharePoint UI
Changing the master page using the SharePoint user interface

Thursday, 2 May 2013

SharePoint Error: Access Denied When Activating Publishing Infrastructure, Site Collection Feature

Description:
When attempting to activate the "Office SharePoint Server Publishing Infrastructure" Site Collection Feature, an "Access Denied" error is presented.

Solution:


* Start > Programs > Administrative Tools > IIS Manager
* Expand the Application Pools node, locate the application pool associated with the site collection that is experiencing an issue
* Right-Click the Application Pool and select "Properties"
* Select the "Identity" tab
* Note the user account
* Start > Programs > Microsoft Office Server > SharePoint 3.0 Central Administration
* Site Actions > Site Settings > Advanced Permissions
* Click "Groups"
* Click "Farm Administrators"
* New > Add Users
* Add Users: Type the name of the Application Pool Identity account
* Give Permission: Add users to a SharePoint group: Farm Administrators
* Add the Application Pool account to the Farm Administrators group
* Send E-Mail: Uncheck (you most likely do not want to send an email)
* Click OK
* Try again to activate the "Office SharePoint Server Publishing Infrastructure" Site Collection Feature

Monday, 22 April 2013

HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Date: Connection: close in Sharepoint 2010

For the above issue, we have to create a site collection for the site to browse. I went and created site collection for the new web application

Central Administration > Application Management under Site Collections > Create Site Collections

Select the web application and select a template to create site collection.

That resolved the issue :)
 

Wednesday, 23 January 2013

How to set the database to read/write in SharePoint 2010


If you verify that the content database is in read-only mode, set the SQL Server Management Studio database to read/write.
To verify that the database is read-only:
  1. Verify that the user account that is performing this procedure is a member of the Farm Administrators group.
  2. On the Central Administration Home page, click Application Management.
  3. On the Application Management page, in the Databases section, click Manage content databases.
  4. On the Manage Content Databases page, select the Web application from the Web Application list.
  5. If Yes appears in the Database Read-Only column for the content database, set the content database to read/write.
To set the content database to read/write:
  1. Verify that the user account that is performing this procedure is a member of the db_owner fixed database role for the content database.
  2. Open SQL Server Management Studio and connect to the database server.
  3. In Object Explorer, expand Databases.
  4. Right-click the database that you want to set to read/write, and then click Properties.
  5. In the Database Properties dialog box, on the Options properties page, under State, select False from the drop-down list next toDatabase Read-Only, and then click OK.
  6. Click Yes.

Tuesday, 22 January 2013

Configuring outgoing email in SharePoint 2010 with Exchange 2010


Launch the Exchange Management Console and navigate to Server Configuration / Hub Transport / New Receive Connector.  The New Receive Connector wizard is invoked.
Enter a descriptive name and ensure “Custom” is selected as the intended use.
Click Next
Leave “All Available IPv4” in your Local Network settings unless you have specific Exchange IP requirements.
Click Next
Edit the IP address of your SharePoint 2010 server.
Click Next
Click New
You will now notice that our SharePoint 2010 Outgoing mail connector is listed with our default Exchange 2010 Receive
Connectors..  

We will now venture into its properties and make a minor permission change.  Click on the “Permission Groups” tab and select Anonymous users.
Click Apply.
Configuring outgoing email in SharePoint 2010 Central Administration
Launch Central Administration and navigate to System Settings / E-Mail and Test Messages / Configure outgoing e-mail settings.
Enter your Outbound SMTP server, i.e. your Exchange server where we created our receive connector and specify a From and Reply-to address.
In outbound SMTP server text box write your exchange server address(servername.exchangedomainname.local , or IP address).
In my case my server name is : Point1, exchange domain name: ads and server IP address is: 192.168.15.110
Ex: Point1.ads.local or 192.168.15.110
Click OK
It is done :)

Friday, 18 January 2013

HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 , Connection: close


Some time we got the below error while creating a new web application and browsed the site:


 
 
HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Date: Tue, 03 Jan 2012 15:44:21 GMT
Connection: close

To resolve the above issue, we have to create a site collection for the site to browse. 

So I created site collection for the new web application
 
Central Administration > Application Management under Site Collections > Create Site Collections 
 
Select the web application and select a template to create site collection.
 
That resolved the issue.

Happy Browsing :)

Friday, 4 January 2013

Script to Disable the Fields in NewForm EditForm in SharePoint

Before adding the following script to the NewForm or EditForm we have to give the Reference of jQuery.js and SPServices.js either in Master Page or in the form where you what to add this script.
<script language="javascript" type="text/javascript">
  $(document).ready(function() {
 
      var isUserOnly = false; //User group member only     
      var isAdmin=false;
      var groupName = "Admin Group";
 
   $().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status)
     
        {
        if($(xData.responseXML).find("Group[Name= Admin Group ']").length == 1)
            {
                isAdmin = true;            
            }
            else
            {
                isUserOnly=true;               
            }
          }
       });
      
       if (isUserOnly)
       { 
            //Disable DropDown
            $("Select[Title='Project']").attr("disabled", "disabled");             
           
           
            var Title =document.getElementById('ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_TextField');
Title.disabled=true;
           
var assignedTo = document.getElementById('ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_downlevelTextBox');
assignedTo.disabled=true;
var assignedTodiv = document.getElementById('ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv');  
assignedTodiv.disabled=true;
var description = document.getElementById('ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_TextField');
description.disabled= true;
var description1  = document.getElementById('ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_iframe');
var StartDate = document.getElementById('ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_DateTimeField_DateTimeFieldDate');
StartDate.disabled=true;
       
//Disable Calendar Image                   
var imgStartDate = document.getElementById('ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_DateTimeField_DateTimeFieldDateDatePickerImage');
imgStartDate.disabled=true;
       
                   
//MultiLine Rich Textbox
description1.disabled = 'disabled';
           
                       
//Disable Dropdown fields
DisableField("Project");
               
//Disable Multiline box     $('#ctl00_m_g_e8d7e5d3_7fc5_4496_b8b6_00a6a4f46062_ctl00_ctl04_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_iframe').contents().find('body').attr('disabled','disabled');
//PeoplePicker
$('nobr:contains("Assigned To")').closest("td").next("td").attr("disabled", "disabled");
$("div[id$='_UserField_upLevelDiv']").attr("contentEditable",false);
$("span[id$='_UserField']").find("img").hide();        
           
       }   
 }); 
//Function to Disable DropDown
 function DisableField(title)
{
    for(var i = 0; i < document.all.length; i++)
    {
        var el = document.all[i];
        // find html element with specified title
        if(el.title == title)
        {
            el.disabled = true; // disable
            // if the next element has a reference to the current element
            // then disable if as well
            if(i < document.all.length - 1)
            {
                var el2 = document.all[i + 1];
                if(el2.outerHTML.indexOf(el.id) > 0)
                {
                    el2.disabled = true;
                }
            }
            break;
        }
    }
}
</script>