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);                
            }
            else
            {
                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!!!

Ref: https://sharepoint.stackexchange.com/questions/114273/sharepoint-2013-search-not-working-ootb

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 "forest:DomainA.com;forest:DomainB.com,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!!!!!

Saturday, 17 December 2016

How to refresh the page after closing dialog in SharePoint?

Below code help is to refresh the page after closing the dialog in SharePoint:

 var options = {
    url: 'https://sp2013dev/sites/dev/Shared%20Documents/Forms/EditForm.aspx?ID=9',
    title: 'My Title',
    allowMaximize: false,
    showClose: true,
    width: 400,
    height: 350,
    dialogReturnValueCallback: function(result){
        if (result == SP.UI.DialogResult.OK) {
            window.location.reload();
        }
        if (result == SP.UI.DialogResult.cancel) {
            //do nothing, modal was closed
        }
    }

  };  
   SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options); 


When you click Save button in model dialog above code refresh the page. And if you click close/cancel it will do nothing and will return to parent page.

Hope this helps....

Reference:http://sharepoint.stackexchange.com/questions/202829/how-to-refresh-page-after-closing-dialog-form-sharepoint-2013

Advantages of Lookup column

Lookup column is field that takes value from the another list and display as a Choice column or Multi select List-Box depending upon the selection.

Below are the advantages of Look column over a Choice dropdown column:

  • The Look up column allows non-admin users to add new choices in dropdown by adding new values in source list
  • You can manage permission at source list per list item. Depending on permission lookup column will show/hide specific items to user based on permission
  • Look up field can be used to make relationship between two lists
  • We can create count related lookup column in source list, which is computed field that computes the number of items in the target list that point to the current item of source list. Here is article on the same.


Set All lists in SharePoint Site to open in dialog

Recently in one of the project I needed to set all list in site to open in dialog. As it was more than 40 lists it was tedious job to do one by one.

A quick search on google gave me below powershell command which helped me to achive the functionality.

$web = Get-SPWeb -Identity http://rootsite/subsite
foreach ($list in $web.Lists)  { $list.NavigateForFormsPages = $false; $list.Update(); }




where false indicates that the list form page is launched in a modal dialog.

Hope this helps

How to restore deleted OOB timer job in SharePoint?

The simple way which I found and worked in my case is, to running below PowerShell script.

The PowerShell script restores the deleted timer job,

$farm = Get-SPFarm  
$farm.TimerService.EnsureDefaultJobs()  
Reference: http://sharepoint.stackexchange.com/questions/137538/how-to-restore-deleted-oob-timer-job

Friday, 16 December 2016

How to add custom CSS file in SharePoint 2013 Team Site MasterPage

There are two different ways to add custom CSS file in Team Site. In both the options you will need to first add your Custom CSS file in document library which is accessible to all users. In below example I have uploaded my custome css file in Site Asset document library.

Option 1:

  • Activate publishing feature on site.
  • Go to Site Action --> Site Settings

















  • Go To Look and Feel and then click on Master Page


















  • Scroll Down and Expand Alternate CSS URL and then browse your CSS Path and Click OK








You can use this option if you have publishing feature enabled, but what if the publishing feature is not enabled and you don't want to enable publishing feature.

In this case you will need modify master page and this is our option 2.

Option 2

  • Open your SharePoint Website in SharePoint Designer 2013.
  • Edit your masterpage and in Head Section add below lines of code. This will add your Custom css file in master page
<!--SPM:<SharePoint:CssRegistration name="&lt;% $SPUrl:~SiteCollection/Style Library/Custom Style/CustomCSS.css %&gt;" runat="server" after="corev15.css"/>-->

This way you can add your Custom CSS file in your SharePoint site.

Friday, 18 December 2015

Birthday reminder using SharePoint list

If you have SharePoint 2007 and up, AND it is the enterprise version of SharePoint, then you can use what's called Information Management Policies.
  1. Create a SharePoint list (custom list template) with all the people (in a people picker field) and their birthday (in a date field)
  2. Create a SharePoint Designer workflow on that list, that has one action: Send an email.  Put the birthday person's name in the TO  box of the email, and make the subject and body say whatever you want. 
  3. Publish the workflow.
  4. Go to the list's advanced settings, and change 'allow mgmt of content types' to YES.
  5. In list settings in the list of content types, there will only be one, called Item.  Click Item.
  6. Click Information Management Policy settings.
  7. Click "define a policy" and click OK.
  8. check the box next to "enable expiration"
  9. next to "a time period based on this item's properties, pick your birthday field + 1
  10. next to 'perform this action" choose to run a workflow
  11. Pick the name of the workflow you created at step 2

This will run every night and if it's a person's birthday they will get an email... the next day.

Friday, 20 November 2015

Modified and Created date in List View not showing current year - SharePoint 2013

In SharePoint 2013, list view we generally face this issue with Created or Modified Date where is done not show the Year. As seen in screenshot:


This is because, by default SharePoint shows date in Friendly format.

A quick workaround we can apply is to

  1. Go to List Settings
  2. Click on Modified or Created date column
  3. Changes Display format to Standard
  4. Done.
Then dates will be displayed in mm/dd/yyyy format.



Friday, 3 July 2015

How to get current year and current month get selected in SharePoint column

I have added Year column in SharePoint list and I want the default value to be current year.
To do this in default value of a column, select calculate value and put below formula in Text box

=TEXT(Today,"YYYY")

Similarly to select current month in moth column put below formula in Text box:

=TEXT(Today,"mmmm")

Hope this helps!!!!

Working with Checkbox in SharePoint

In below code we will see, how to add multichoice chekcbox field in list, add item with checkbox field and get value from chekcbox field.

using System;
using System.Collections.Specialized;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static string listTitle = "My Custom List";
        static string fieldTitle = "Gift Options";
        static string fieldInternalName = null;

        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPList list = web.Lists.TryGetList(listTitle);
                    if (list != null)
                    {
                        // Add a multichoice field to the list.
                        StringCollection choices = new StringCollection();
                        choices.Add("Gift wrap");
                        choices.Add("Gift card");
                        choices.Add("Include gift receipt");

                        fieldInternalName = list.Fields.Add(fieldTitle, SPFieldType.MultiChoice, false, false, choices);
                        list.Update();

                        // Get a reference to the field.
                        SPFieldMultiChoice choiceField = (SPFieldMultiChoice)list.Fields.GetField(fieldInternalName);

                        // Create a field value with all choices selected.
                        // (A CheckBoxChoiceField control would have all boxes checked.)
                        SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue();
                        foreach (string choice in choices)
                        {
                            values.Add(choice);
                        }

                        // Add an item to the list.
                        SPListItem item = list.Items.Add();
                        item[SPBuiltInFieldId.Title] = "Test item";
                        item[choiceField.Id] = values;
                        item.Update();

                        // Get the value of the field in the item.
                        string rawValue = item[choiceField.Id].ToString();
                        SPFieldMultiChoiceValue typedValue = new SPFieldMultiChoiceValue(rawValue);

                        // Print the value.
                        Console.WriteLine("The raw value is {0}", rawValue);
                        Console.WriteLine("The value delimiter is {0}", SPFieldMultiChoiceValue.Delimiter);
                        for (int i = 0; i < typedValue.Count; i++)
                        {
                            Console.WriteLine("The value at index {0} is {1}", i, typedValue[i]);
                        }
                    }
                }
            }
            Console.WriteLine("\nPress ENTER to continue....");
            Console.Read();
        }
    }
}

Hope this helps!!!









How to download all deployed wsp solution files in SharePoint

Usually SharePoint admin guys takes backup of content DB and all physical files if they want to create replica of existing SharePoint site when actual site is down.

But that will not complete solves the solution, if there are any custom solutions already deployed.

So, admin guys needs those solution files.
To get those solution files which are deployed in SharePoint use the following power shell command to get all deployed solution files.

$pathName = "<PATH to Save files>"
foreach ($solution in Get-SPSolution)   
{
     $solid = $Solution.SolutionID
     $title = $Solution.Name
     $filename = $Solution.SolutionFile.Name
     $solution.SolutionFile.SaveAs("$pathName\$filename") 
}

Ref: http://ukreddysharepoint2010.blogspot.in/2015/05/how-to-download-all-deployed-wsp.html

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