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.!!!

Friday, 2 June 2017

Is free version available in SharePoint 2016

Until SharePoint 2013, there was a SharePoint foundation version available, which is free. Unfortunately in SharePoint 2016 it is deprecated.

What's deprecated or removed from SharePoint Server 2016

But still if you want to try out SharePoint 2016, you can use SharePoint 2016 trial .

You can use one of the following trial product keys. The trial period is 180 days.
  • Enterprise trial product key: NQGJR-63HC8-XCRQH-MYVCH-3J3QR
  • Standard trial product key: RTNGH-MQRV6-M3BWQ-DB748-VH7DM
Please note
  1. You can not extend trial period for SharePoint
  2. You can convert to a licensed installation at any time during the trial or after the trial has expired by entering the appropriate product key in Central Administration.
  3. If your company have MSDN subscription, you will able to use SharePoint free for development purpose, but you can't use it in Production environment.
Hope this helps!!!

Saturday, 27 May 2017

Custom EventReceiver Feature not appearing in manage feature list

Recently while deploying event receiver on one of the web application i faced a strange issue. My solution file got deployed successfully, but the feature was not visible in "Manage Site Features" of the site for which I have to activate the event receiver.

The web application was migrated from 2010 to 2013.

The web results returned from google search was not resolving my issue.

Since it was not available in "Manage Site Features" I tried to activate using powershell, using below command:
Enable-SPFeature -identity  -URL yoursiteURL
The command failed with error
The feature is not a Farm Level feature and is not found in a Site level defined by the Url [Site Collection Url].

Then google search for this error message, return the actual cause for the issue. While migrating site from 2010 to 2013, we have not done the visual upgrade of the site. And because of this the feature was not available in "Manage Feature List"

So the solution was to install wsp file with compatibility level.
Install-SPSolution -Identity "Solution.wsp"  GACDeployment -CompatibilityLevel{14,15}

This resolved the issue, and feature appeared in Manage Site Features. Hope this helps.!!!!!

Thursday, 11 May 2017

Connect SharePoint WebApplication to another domain after two way trust

If two way trust is already set. Then you can run below stsadm commands from your server:

Step 1:

First, you have to set an encryption key on all web servers in your farm so that the stored credentials can be encrypted:

Just to be clear, you have to run this on all web servers in your farm and the "AnyKey" value has to be set to the same value on all of those servers.

STSADM.exe -o setapppassword -password AnyKey
where "AnyKey" is any value.

For example,
STSADM.exe -o setapppassword -password B1gL0ngPassw0rd

Step 2

Next, you have to run below stsadm command to search users from other domain in people picker and give them access

stsadm -o setproperty -pn peoplepicker-searchadforests -pv ";,DomainB\login,password" -url "Your webapp url"

*DomainA: is a domain on which SharePoint installed
Domain B: is a new domain which you have to connect to sharepoint

Once above command runs successfully you will able to search users from DomainB in sharepoint portal which is on DomainA.

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