Wednesday, December 10, 2014

SharePoint Publishing Workflow - The workflow could not set content approval status. Enable content moderation for this list and run the workflow again.

This is regarding SharePoint Out Of Box Publishing Approval Workflow issue in SharePoint 2010.

1. Add  an Out of Box Publishing Approval workflow to a SharePoint document library (e.g Pages)
2. Create a Page and Publish the page.
3. The workflow assigns task to Content Approver to Approve/Reject the changes
4. When the Content Approver approves/rejects the page, the status is updated as Approved/Rejected.
5. But when we navigate to the page, it still shows "Waiting for approval".

The issue occurs in April 2012 CU of SharePoint 2010 (version 14.0.6120.5000). 
To fix the issue, install the higher version of CU or register older version of dll of Microsoft.Office.Workflow.Actions.dll (14.0.6108.5000in GAC

Reference
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/e87c50e0-e7ed-41f0-bdb5-b16a3cf6828d/ootb-workflow-gives-error-when-user-rejects-in-the-document-in-publishing-a-major-version
Create Reminder mails on Task List


Below are Out of Box steps to send task due reminder mails in SharePoint. The below approach is applicable for both SharePoint 2010 and SharePoint 2013.

1. Create Task list

2. Create a workflow using SharePoint Designer to send emails to users. Include condition to send mails only for due tasks/overdue tasks

3. Uncheck all the checkboxes in Start Options for the workflow

4. Publish the workflow

5. In Task list navigate to List Settings

6. Click on Information management policy settings  - >Task


7. Click on Enable Retention



8. Click on Add a Retention stage



9. Enter settings for Time Period as Due Date + 0 days


10. In Actions, select Start a workflow and select the workflow created

11. If reminder mail is to be sent every day, then check the checkbox for Recurrance and enter 1 day


12. Navigate to Central Admin -> Monitoring



13. Click on Review Job Definitions

14. Click on Information Management Policy .

15. Configure it to run Daily. Default setting is to run every Friday at 11 pm

16. Click on Expiration Policy


17. Configure it to run Daily, couple of hours after Information Management Policy runs. Default setting is to run every Saturday at 11 pm

18. Now the reminder mails will be sent daily once the tasks are due till its completed

References




Friday, October 17, 2014

Retrieve count of documents in Search Index - SharePoint 2013

To retrieve count of  documents in search index, save below script as .ps1 file and run it using powershell


<# 
.SYNOPSIS 
    Script to get the total number of indexed documents  
.DESCRIPTION 
    For the given Search Application, return the total number of indexed documents. 
    This will be the sum of indexed documents for all index partitions. 
.PARAMETER SearchApplication 
    Search application to use.   Multiple SSA's can be specified by 
    piping them in to the script.  In that case the result will be an array 
    of document counts, one for each SSA 
.EXAMPLE 
    Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchIndexedDocumentCount.ps1 
    88123 
.LINK 
http://gallery.technet.microsoft.com/ScriptCenter 
.NOTES 
  File Name : Get-SPEnterpriseSearchIndexedDocumentCount.ps1 
  Author    : Matthew King 
 
#> 
 
[CmdletBinding()] 
param([Parameter(ValueFromPipeline=$True)] 
      [Microsoft.Office.Server.Search.Cmdlet.SearchServiceApplicationPipeBind]$SearchApplication) 
 
Process { 
    $ssa = Get-SPEnterpriseSearchServiceApplication $SearchApplication 
    $topo = Get-SPEnterpriseSearchTopology -SearchApplication $ssa | ? { $_.State -eq 'Active'} 
    $count = 0 
    Get-SPEnterpriseSearchComponent -SearchTopology $topo | ` 
        ? { $_ -is [Microsoft.Office.Server.Search.Administration.Topology.IndexComponent] } | ` 
        Sort-Object IndexPartitionOrdinal -Unique | % { $component = $_ 
            [int]$c = $ssa | Get-SPEnterpriseSearchStatus –HealthReport –Component $component.Name | ` 
                ? { $_.name -match 'number of documents\[' } | % { $_.message } 
            Write-Verbose ("{0} {1} {2} " -$ssa.Name, $component.Name, $c) 
            $count +$c 
    } 
    $count 
}

Reference
https://gallery.technet.microsoft.com/office/Script-to-report-total-88056b1b

Delete Search Index - SharePoint 2013

To delete search index in SharePoint 2013, it can be done by Central Admin or by powershell. To delete it using powershell run below command

(Get-SPEnterpriseSearchServiceApplication).Reset($true,$true)

If it takes a long time to delete index and ultimatley if it gives time out error, follow below steps


  1. Stop the Windows SharePoint Services Timer service (Found in Windows Services)
  2. Navigate to the cache folder
  3. In Windows Server 2008, the configuration cache is in the following location:
  4. Drive:\ProgramData\Microsoft\SharePoint\Config
  5. In Windows Server 2003, the configuration cache is in the following location:
  6. Drive:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config
  7. Locate the folder that has the file "Cache.ini"
  8. (Note: The Application Data folder may be hidden. To view the hidden folder, change the folder options as required)
  9. Back up the Cache.ini file.
  10. Delete all the XML configuration files in the GUID folder. Do this so that you can verify that the GUID folder is replaced by new XML configuration files when the cache is rebuilt.
  11. Note When you empty the configuration cache in the GUID folder, make sure that you do not delete the GUID folder and the Cache.ini file that is located in the GUID folder.
  12. Double-click the Cache.ini file.
  13. On the Edit menu, click Select All. On the Edit menu, click Delete. Type 1, and then click Save on the File menu. On the File menu, click Exit.
  14. Start the Windows SharePoint Services Timer service
  15. Note The file system cache is re-created after you perform this procedure. Make sure that you perform this procedure on all servers in the server farm.
  16. Make sure that the Cache.ini file in the GUID folder now contains its previous value. For example, make sure that the value of the Cache.ini file is not 1.



Reference
http://blogs.technet.com/b/maruntz/archive/2013/04/10/reset-the-content-index-of-sharepoint-server-2010-via-powershell.aspx
https://social.technet.microsoft.com/Forums/sharepoint/en-US/ede11fc6-59a7-47be-893d-dc1ea4c88879/cant-reset-index-sharepoint-2013




Thursday, March 20, 2014

Export GridView to excel in Visual Webpart in SharePoint

Declare GridView and Button as below

<asp:GridView ID="gridViewPermission"  runat="server" >
     </asp:GridView>

<asp:Button ID="buttonExportUsers" runat="server" Text="Export Users" onclick="ButtonExportUsers_Click" OnClientClick="window.setTimeout(function() { _spFormOnSubmitCalled = false; }, 10);"/>

Note the OnClientClick event for button

There are two approaches to export it

1. Export to csv file
2. Export to excel file



1. Export to csv file

            StringBuilder sb = new StringBuilder();
            GridViewRow grHeader = gridViewPermission.HeaderRow;
            int counter = 0;

            foreach (TableCell tc in grHeader.Cells)
            {
                sb.Append("" + tc.Text + " ,");
                counter++;
            }
            sb.AppendLine();

            foreach (GridViewRow gr in gridViewPermission.Rows)
            {
                foreach (TableCell tc in gr.Cells)
                {
                    sb.Append("" + tc.Text + " ,");
                }
                sb.AppendLine();
            }

            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.AddHeader(" content-disposition", " attachment; filename=" + strSite + "_Users_" + strDate + ".csv");
            Response.ContentType = " text/csv";
         
            Response.AddHeader(" Pragma", " public");
            Response.Write(sb.ToString());
            Response.End();


2. Export to excel file

Response.ClearContent();
            Response.AddHeader("content-disposition", " attachment; filename=" + strSite + "_Users_" + strDate + ".xls");
            Response.ContentType = "application/vnd.ms-excel";
            string tab = string.Empty;
            GridViewRow grHeader = gridViewPermission.HeaderRow;
            foreach (TableCell headerCell in grHeader.Cells)
            {
               Response.Write(tab + headerCell.Text );
               tab = "\t";
            }

            Response.Write("\n");
            foreach (GridViewRow gridViewRow in gridViewPermission.Rows)
            {
                tab = string.Empty;
                foreach (TableCell dataCell in gridViewRow.Cells)
                {
                    Response.Write(tab + dataCell.Text.Replace(CommonFunctions.SpaceText,string.Empty) );
                    tab = "\t";
                }
                Response.Write("\n");
            }
            Response.End();

References - http://www.fewlines4biju.com/2011/11/export-gridview-data-to-excel-aspnet.html

Thursday, March 06, 2014

Configure ElasticSearch on Windows


2.      Download the latest java SDK if not installed on the system.

3.      Navigate to url http://www.elasticsearch.org/download/

4.      Download the zip version of elasticsearch for windows.

5.      Extract the files to a folder

6.      Set JAVA_HOME variable if not set

a.       Click on Start, right click on My Computer -> Properties
b.      Click on Advanced system settings



c.       In Advanced tab click on Environment variables



d.      If JAVA_HOME variable is not present here, click on New and enter details for Variable Name and Variable Value. Variable value will be path where java sdk is installed.



e.       Save the value

7.      Navigate to the folder where elastic search files were extracted.

8.      Navigate to bin folder and double click on elasticsearch.bat to run.



9.      Navigate to http://localhost:9200/ url and below screen should appear if successfully installed.





1.  Install Google Chrome plug-in Sense to run elasticsearch queries.