Thursday, 10 August 2017

How to get Financial Year from provided date programatically in C#?

We can use below code to get Financial year start date and end date from supplied date.

 Public void getFY(DateTime dt)
            string period = "";
            DateTime FYStart, FYEND;

            int year = dt.Year;
            int month = dt.Month;

            if (month < 4)
                FYStart = new DateTime((year - 1), 4, 1);
                FYEND = new DateTime(year, 3, 31);                
                FYStart = new DateTime(year, 4, 1);
                FYEND = new DateTime(year + 1, 3, 31);                

Hope this helps!!!!

Tuesday, 11 July 2017

Error: The Template property must be initialized before rendering this control. It cannot be null when the control is rendered.

While using SPGridView with AllowGroupCollapse=True was returning me this error on Binding.

The Template property must be initialized before rendering this control. It cannot be null when the control is rendered.

Adding EnableViewState = False resolved the issue.

Hope this helps!!!!

Thursday, 6 July 2017

Error: Group Not Found in SharePoint

Today while programatically adding user in SharePoint group I was getting error "Group Not Found" in my custom workflow.

The error was getting thrown at below line:
SPGroup grpViewer = workflowProperties.Web.Groups["GroupName"];

After some digging, I found that the error was coming since the group was not having permission on site. After giving read permission for the group on site, the error was gone.

Hope this helps!!!!

Monday, 19 June 2017

Caml Query to filter people and group column with current user

Use below caml query to get records for current user by filtering People and Group column.

<Where><Eq><FieldRef Name='ColumnInternalName' /><Value Type='Integer'><UserID Type='Integer'/></Value></Eq></Where>

Hope this helps!!!!

Powershell to get display name and internal name of SharePoint list columns

Below is the Powershell script to get column information from SharePoint list to .csv file.

$url = "Your SharePoint Site URL"
$listName = "List Name"
$path ="c:\Columns.csv"

$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
$list.Fields | select Title, InternalName |  Export-Csv -path $path

Hope this helps!!!!

Tuesday, 6 June 2017

SharePoint 2013 Search Stopped Working

All of sudden one day our search started to throw error for "Something went wrong", the ULS logs were showing below error:
The processing of item fails with error Cannot plan query for index system SP6bd7dedd292c. Index fragment '0' has no available cells.
Basically it appears the search index partition becomes corrupted.

Following steps resolved the issue:
  1. Stop the Timer Service
  2. Clear the configuration cache - Find in %SystemDrive%\ProgramData\Microsoft\SharePoint\Config\ the folder where the file cache.ini exists
  3. Delete every file from this folder EXCEPT cache.ini
  4. Open cache.ini, delete the content and put '1' (without the quotes) in it and save the file.
  5. Restart the Timer Service.
  6. Reset the Index
  7. Perform Full crawl
Hope this helps!!!


Saturday, 3 June 2017

How to get count of document libraries in a SharePoint site using SSOM?

To get the count of document libraries, we can use below simple code in SSOM:

using(SPSite site = new SPSite("https://yoursiteURL"))
  using (SPWeb web = site.OpenWeb())
    SPListCollection librarycollection = Web.GetListsOfType(SPBaseType.DocumentLibrary);
    int count  = librarycollection .Count;

Sweet and Simple. Hope this helps.!!!
Related Posts Plugin for WordPress, Blogger...