Wednesday, March 1, 2017

System.Web.HttpException: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.

To fix this issue we have to do two changes in web.config file.

First open the web.config file from "C:\inetpub\wwwroot\wss\VirtualDirectories\" Web application Folder"".


  1.  Add the below code on module section.

<add name="Session" type="System.Web.SessionState.SessionStateModule" />




  1. Modify   enableSessionState = "false" to enableSessionState = "true" under pages section as below
<pages enableSessionState="true" enableViewState="true" viewStateEncryptionMode="Always" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">


Tuesday, February 21, 2017

Using PowerShell script how to increase the SharePoint site size.



Power shell command to increase the site size.

    Add-PsSnapin Microsoft.SharePoint.PowerShell

## SharePoint DLL
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$docSize = 524288000
$webservice = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$webservice.MaxTemplateDocumentSize = $docSize
$webservice.Update()

Using sharepoint PowerShell script how to save the site templates in web application.

$WebAppURL = "http://devportal.local"
$featureFolderName = "PublishingWeb"

$SiteCollections = Get-SPSite -WebApplication $WebAppURL -Limit All

foreach($Site in $SiteCollections)
{
    #Get all WebSites
    $WebsCollection = $Site.AllWebs
              
    #Loop through each WebSite
    foreach($Web in $WebsCollection)
    {
                    if ($Web.AllProperties["SaveSiteAsTemplateEnabled"] -eq "false")
                                {
                                    $Web.AllProperties["SaveSiteAsTemplateEnabled"] = "true"
                                                $Web.Update();
                                }
                  
                    $siteName = $Web.Name
                    $siteTitle = $Web.Title
                                $siteDescription = $Web.Description
                  
                                write-host "Save Site: " $siteTitle
                              
                    $Web.SaveAsTemplate($siteName,$siteTitle,$siteDescription,1)
                }
}


Sunday, February 19, 2017

Create Auto increment number Column in SharePoint List

Using below code we can show auto increment column number in SharePoint list.First download the Sputility.js file and jquery files after that create a SNO column with



<script src="/SiteAssets/jquery-3.1.1.js"></script>
<script src="/SiteAssets/sputility.js"></script><script>


    // Get the current Site
    var siteUrl = '/';

    function retrieveListItems() {

        var clientContext = new SP.ClientContext(siteUrl);
        // Get the liste instance
        var oList = clientContext.get_web().get_lists().getByTitle('Test List');

        var camlQuery = new SP.CamlQuery();

        // Get only the last element
        camlQuery.set_viewXml('<Query><OrderBy><FieldRef Name=\'ID\' Ascending=\'False\' /></OrderBy></Query><RowLimit>1</RowLimit></View>');
        this.collListItem = oList.getItems(camlQuery);

        clientContext.load(collListItem);

        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));      

    }

    function onQuerySucceeded(sender, args) {

        var listItemInfo = '';

        var listItemEnumerator = collListItem.getEnumerator();

        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();

            var listItemInfovalue = oListItem.get_item('SNO');


 

            // create the new id
            SPUtility.GetSPField('SNO').SetValue(parseInt(listItemInfovalue) + 1);
        }

        console.log(listItemInfo.toString());
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }



$(document).ready(function(){
    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
    });</script>

Wednesday, February 15, 2017

This server machine in the farm does not have a 64 bit version of Windows Server 2008 SP2 or higher installed.

Solution:

 If you are planning to perform an in-place upgrade to SharePoint 2010, please upgrade the server machines in your farm to a 64 bit edition of Windows Server 2008 SP2 or higher, or migrate the current content databases from this farm to a new farm with servers running 64 bit edition of Windows Server 2008 SP2 or higher. Before attempting to install or upgrade to SharePoint 2010, please ensure that you run the SharePoint 2010 pre-requisites installer beforehand to ensure you have the correct set of prerequisites and patches installed. 

Sunday, February 12, 2017

Pragmatically approve the SharePoint workflow task items.

using below code we can approve the workflow task items.


 using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
            {

                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["TestList"];
                    SPListItem item = list.GetItemById(47);

                    SPWorkflowTaskCollection taskCollection = new SPWorkflowTaskCollection(item, new SPWorkflowFilter());

                    foreach (SPWorkflowTask task in taskCollection)
                    {
                        //Check if the task is the manager's approval task
                        if (task[task.Fields["Status"].InternalName].ToString() != "Completed")
                        {
                            Hashtable ht = new Hashtable();
                            ht[SPBuiltInFieldId.Completed] = "TRUE";
                            ht["Completed"] = "TRUE";
                            ht[SPBuiltInFieldId.PercentComplete] = 1.0f;
                            ht["PercentComplete"] = 1.0f;
                            ht["Status"] = "Completed";
                            ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)task.Web.Language, false), Strings.WorkflowStatusCompleted, new object[0]);
                            ht[SPBuiltInFieldId.WorkflowOutcome] = "Approved";
                            ht["TaskStatus"] = "Approved";
                            ht["FormData"] = SPWorkflowStatus.Completed;

                            web.AllowUnsafeUpdates = true;
                            SPWorkflowTask.AlterTask((task as SPListItem), ht, true);

                        }
                    }

                }
            }

Friday, February 10, 2017

Wednesday, February 8, 2017

How to add the values in sharepoint List choice field programmatically.

Generally SharePoint choice field will be used to display choice options.Choice field can be displayed using Drop-Down Menu,Radio Buttons and Check boxes.
Using below code we can add the values in choice field SharePoint List programmatically in  .I have used  C# and SharePoint API in this code.

            using (SPWeb web = SPContext.Current.Site.OpenWeb())
            {

                //Get the list

                SPList list = web.Lists["Test List"];
                //Get the Choice filed using SPFieldChoice

                SPFieldChoice choicefield = (SPFieldChoice)list.Fields["MyChoice"];
                web.AllowUnsafeUpdates = true;
                //Add some values

                choicefield.Choices.Add("Test 4");

                choicefield.Choices.Add("Test 5");

                //Update the column for the changes to take affect

                choicefield.Update();

                web.AllowUnsafeUpdates = false;


            }

How to cancel the workflows using SharePoint object model.

Solution: Using below code you can cancel the running workflows. it will work for default  and third part workflows like Nintex, K2 etc. First to cancel the active workflow must and should we have to use SPSecurity.RunWithElevatedPrivileges method.
Note: Please change list name and pass the item id value in GetItemById() method as per your logic.
              SPSecurity.RunWithElevatedPrivileges(delegate()
                    {

                        using (SPSite spsite = new SPSite(SPContext.Current.Web.Site.ID))
                        {

                            using (SPWeb spweb = spsite.OpenWeb())
                            {

                               SPWorkflowManager spmanager = spsite.WorkflowManager;

                                //pass the list item id value in GetitemById method.

                               SPListItem spitem = spweb.Lists["SampleList"].GetItemById(27);

                               spitem.Web.AllowUnsafeUpdates = true;
                    foreach (SPWorkflow workflow in spmanager.GetItemActiveWorkflows(spitem))
                    {

                                    SPWorkflowManager.CancelWorkflow(workflow);

                    }

                                spitem.Web.AllowUnsafeUpdates = false;

                            }

                        }


                    });

The workflow name is used elsewhere on this site. Please choose another name.

Solution:
To fix this issue you have to remove the reference folder from NintexWorkflows library. To open Nintexworkflow library you have to go to: your site URL/NintexWorkflows. Once you open the library check the folder name and delete the reference.

How to Add, Update and Delete List Items Programmatically in SharePoint.

Using below code you can add,update and delete the SharePoint list items.
       using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
            {

                using (SPWeb web = site.OpenWeb())
                {

                    web.AllowUnsafeUpdates = true;
                    SPList list = web.Lists["Test List"];
                    //Code for add the values in List

                    SPListItem item = list.Items.Add();

                    item["Title"] = "Test Title";

                    item["Name"] = "Test Name";

                    item.Update();

                    //Code for updating the List items

                    SPListItem itemUpdate = list.GetItemById(1);

                    item["Name"] = "update Name";

                    itemUpdate.Update();
                    // Code for deleting  the List items

                    SPListItem itemDelete = list.GetItemById(1);

                    itemDelete.Delete();
                    web.AllowUnsafeUpdates = false;

                }


            }

Using Event Receiver how to restrict the users to delete the documents in SharePoint Document library.

Solution:
First we have to create the event receiver using visual studio after that place the below code.Please modify the list title and error message and deploy the the event receiver from visual studio solution explorer.
        public override void ItemDeleting(SPItemEventProperties properties)
        {

            try
            {

                //base.ItemDeleting(properties);

                if (properties.ListTitle == "Sample Documents")
                {

                    properties.ErrorMessage = "You are not allowed to Delete the documents";

                    properties.Status = SPEventReceiverStatus.CancelWithError;

                    properties.Cancel = true;

                }

            }

            catch (Exception ex)
            {

                properties.Status = SPEventReceiverStatus.CancelWithError;

                properties.ErrorMessage = ex.Message.ToString();

                properties.Cancel = true;

                //throw;

            }

        }

Exception from HRESULT: 0x80131904

Solution:
If you face this error in SharePoint first check your SharePoint front-end and back-end servers , and also check the SharePoint and SQL servers  services ,because mostly this issue occur if servers are down.

Migration from MOSS 2007 to SharePoint 2010

First you have to prepare the new front-end and backend servers with SharePoint 2010 and SQL server 2008R2 to migrate the sites.
After that please follow below steps.
Step 1:
Stop all services of MOSS 2007
Cmd –> (Services.msc)
Step 2:
Copy MDF and LDF files of SQL server 2005 and paste in SQL server 2008 on below Path
C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA
Step 3:
Open SQL server 2008 management studio
Select the Databases –> Attach…



Step 4:
Click on Add… button as shown below screen.


Step 5:
Select MDF and LDF files and Click on OK.

Step 6:
Create one web application in SharePoint 2010 Sever.
Step 7:
Run the below command in command prompt as administrator to restore the Moss 2007 site database to SharePoint 2010 website.
Stsadm -o addcontentdb –url “http://server06:1405” -databasename “7755″
Here http://server06:1405 new SharePoint site URL and 7755 is database name.


Step 8:
Open web application now you will see still UI in 2007 format.


Step 9:
We have to upgrade UI design using Visual Upgrade option to get SharePoint 2010 UI as below.
Select Site Actions –> Click on Visual Upgrade.



Step 10:
From the below screen select 3rd option Update the user interface and Click OK.


Step 11:
Now after upgrade we will see SharePoint 2010 UI as below.


Step by step by installation of SharePoint 2013







 For the SharePoint 2013 installation first we have to create the SharePoint service accounts in active directory and need to provide the required permissions as below.
SharePoint Service Accounts:
User AccountLocal AdminDomain

Account
Purpose
sqlsetupadminYesYesWe have to Install SQL Server with this account and this account will be the owner of SQL Instance.
sqlserviceaccNoYesThis is a service account and when the SQL Server Installation configures MSSQLSERVER and SQLSERVERAGENT services to run under this account.
spsetupadminYesYesThis account which use to Install the SharePoint. This account needs to have privileges to Security Admin and DB creator in the SQL Server. This is the only account we need to give the SQL Server permissions manually.

This account is used by Human been who access the SharePoint for Administrative purposes such as add servers to farm, Remove servers etc.
spfarmadminNoYesThis is the service account which is use to configure services in the farm such as timer jobs, internal services etc.
Now we have to install the SQL server in back-end sever .for that login with SQL Admin (sqlsetupadmin) account. Run the SQL software setup file and click on the “New SQL Server stand-alone installation or add features to an existing insulation” option as below.

After that we will see below screen. As per below screenshot we have to turn off the Windows Firewall and click on the Re-run button to remove the windows Firewall warning and for successful  installation.

Windows Firewall warning has been removed. Click on Next button in below screen.


Select the “SQL Server Feature Installation” option to choose the required features.


Choose the feature you want to install. Do not select all features if you will not use them, as this will use server resources that could be used by the SQL Server database engine or Windows. I have selected the SQL Server Database Engine along with a few shared features as shown in the below screenshot. Once you select the required feature then click on “Next”.


From below screen select “Default instance” and click Next.


Install the all the features using “sqlserviceacc” account as below.

Under “Server Configuration” select Windows authentication mode option if you want you can choose Mixed Mode authentication as per your requirement. Click on “Add Current user” to add sqlsetupadmin as a SQL administrator.



Select Install and configure option from below screen and click next.

From below screen click on “Add Current User” to give the sqlsetupadmin permission Distributed Replay controller and click on next.

SQL installation has been successfully completed.


After installation of SQL Server we need to give the sys admin permissions to spsetupadmin to install the SharePoint.


Add the permission from SQL Server management studio as below.

Now login as a spsetupadmin to install the SharePoint.
Run the SharePoint setup file and install the prerequisites from below screens.



Enter the Product key and click on continue.

After installation we have to configure the SharePoint product configuration for that please click on next.

Select “Yes” and click on “Next”.

Now we are creating fresh SharePoint installation so select “Create a new server farm” option as below and click Next.

Mention the data base server name, data base name (for the configuration data base) and specify the form account user name and password after that click “Next”.

In below screen we have to mention “Passphrase” password and click “Next”. Always please remember this password, because if want to rerun the product configuration we have to use this.

From below screen mention the port number for the central admin site and select NTLM authentication. Click “Next”.

Click on Finish.

SharePoint installation has been successfully completed.