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

When to use BeforeProperties, AfterProperties, properties.ListItem in event receiver

Below table give us the idea on when to use BeforeProperties, AfterProperties, properties.ListItem in event receiver

Library
BeforeProperties
AfterProperties
properties.ListItem
ItemAdding
No value
No value
Null
ItemAdded
No value
No value
New value
ItemUpdating
Original value
Changed value
Original value
ItemUpdated
Original value
Changed value
Changed value
ItemDeleting
No value
No value
Original value
ItemDeleted
No value
No value
Null

Hope this helps!!!

How to find out SPUser belongs to Specific Group

How can I find out programmatically if current user belongs to some group on sharepoint website?

We can use below code:

SPWeb site = SPContext.Current.Web;
SPGroup managerGroup = site.Groups["Your_Group_Name"];

bool isManager = site.IsCurrentUserMemberOfGroup(managerGroup.ID);

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