Navigation

Saturday, 29 August 2015

New features in C# .NET 6.0

Below are the new features expected to come in upcoming .NET release C# 6.0
  1. Auto Property Initializer 
  2. Primary Constructor and its Body
  3. Import Static members with the help of "using"
  4. Exception Filters
  5. Dictionary Initializer
  6. Conditional access operator to check null values.
Let's see brief description about each below.

1. Auto Property Initializer 

we can initialize property values directly without declaring private fields or within the constructor. See below example

Before C# 6.0

public class Employee
{
    public Employee()
    {
        Salary = 10000;
    }

    public int Salary { get; set; }

    private string _company = "Your Company";

    public string Company
    {
        get { return _company; }
        set { _company = value; }
    }
}

We can write above code using C# 6.0 as below.

public class Employee
{
    public int Salary { get; set; } = 1000;

    public string Company { get; set; } = "Your Company";
   
}


So no more required constructor or private fields to initialize auto properties.

2. Primary Constructor and its Body

In C# 6.0, we can define constructor side by class name itself. Below is the example

Before c# 6.0 

public class Employee
{
    public Employee()
    {
        Salary = 10000;
        Company = "Your Company";
    }

    public int Salary { get; set; }

    public string Company { get; set; }
}

In C# 6.0 


public class Employee(int salary, string company)
{
    public int Salary { get; set; } = salary;

    public string Company { get; set; } = company;
}


3. Import Static members with the help of "using"

In C# 6.0 we no need to access static members with the help of class name, instead we can import static class with help of "using" as we do for namespaces so that we can directly access static variables.

Before C# 6.0

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your username");
        }
    }
}

In C# 6.0

using System.Console;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteLine("Enter your username");
        }
    }
}



Sunday, 10 May 2015

Microsoft.Workflow.Client.ActivityValidationException: Workflow XAML failed validation due to the following errors: Failed to create a 'ListId' from the text

If you are planning to move SharePoint 2013 List workflow from development site to Production environment you must check all the resources (Like Lists/document library or SP groups etc) are existing in the production site before importing workflow package. 

Check https://msdn.microsoft.com/en-us/library/office/jj819316.aspx link for more information about how to package and deploy SharePoint designer workflows.

In one scenario I forgot to create one dependency List that i used in the target workflow and tried to activate the related workflow feature after uploading the workflow package into the Solution Gallery, because of this I encountered the error Microsoft.Workflow.Client.ActivityValidationException: Workflow XAML failed validation due to the following errors: Failed to create a 'ListId' from the text.... 

You will also see some related useful information in the above error (I have removed the some of error message part as that was not required to mention here). 

So I have created the dependency list and again tried to activate the feature.. even this time  I encountered same error because there was already workflow has been created  during the first error so we need to delete that workflow using SharePoint designer and retry activating the feature related to workflow package. This solved my problem and workflow has been created successfully.


Saturday, 9 May 2015

the object used for the selected operation could not be found sharepoint designer

Today i have created list with the help of existing list template, by the time the site is opened in the SharePoint designer. After successfully creating list I refreshed items in designer to check the newly created list. Interesting thing is here I can see the list that I have created but when I try to open the properties of that list, I encountered "the object used for the selected operation could not be found" error. I tried refreshing designer  too many times but in vain.

Solution: I have just closed all the SharePoint Designer windows and reopened the site, this time it worked perfectly. Looks like not big issue but, there at the movement designer may failed to get all the information from the server.

Sunday, 23 November 2014

Constraint violation occurred active directory C# Directory Services

While creating user accounts in active directory using Directory Services through C# we commonly encounter error  Constraint violation occurred.
This is an error which gives the generalized error message where developers can not find the reason of exception or error details exactly. Same way i have wasted 2 hours of time on this error to find out the exact reason and common scenarios related to it. This is because of following cases,

1. When we try to update the country attribute  'c' with string: - Country attribute should be set with only 3 characters or less, if we try to update 'c' attribute with string more than 3 characters length we face Constraint violation occurred error.

In the same way if we try to update any attribute with data that violates it's constraints we may face this generalized error so please make sure you are updating attributes with correct information.

For all attributes information please follow my previous post 

Note: Exception is thrown only at de.CommitChanges(); (de is instance of DirectoryEntry type) irrespective of all lines of code where we set attributes before this line

Sunday, 16 November 2014

Why Microsoft and Why enterprises use office 365 over google apps

Most of us think that, is there any replacement for Microsoft Office but, Microsoft has its own market with its improved office 365. Please check below link for more information
http://www.whymicrosoft.com/see-why/enterprises-choose-office-365/

Tuesday, 11 November 2014

User Attributes in Active Directory

Click this link to download PDF which has all attributes information of Active Directory user objects.

For more information please follow this link


Thursday, 30 October 2014

Installing Windows Service with Command Prompt and Visual Studio Command Prompt

We can install windows service into Services on windows server with the help of InstallUtil.exe a
command line utility using 

1. Using Visual Studio Command Prompt 
2. Command Prompt

InstallUtil.exe is the command line utility which is installed with .Net frame work and its path is %WINDIR%\Microsoft.NET\Framework[64]\<framework_version>

I. Using Visual Studio Command Prompt 
  1. On the Windows Start menu or Start screen, choose Visual Studio Visual Studio ToolsDeveloper Command Prompt.
    A Visual Studio command prompt appears.
  2. Access the directory where your project's compiled executable file is located.
  3. Run InstallUtil.exe from the command prompt with your project's executable as a parameter:
           installutil <yourproject>.exe



Sunday, 25 May 2014

Filtering ULS Log using Power Shell

It is very handy using Get - SPLogEvent power shell command to retrieve logs from ULS in certain time period .

Use bellow command syntax 

get-splogevent -starttime (get-date).addminutes(-20) | where-object { $_.correlation -eq “b66db71a-3257-4470-adf9-5c01dc59ecb3″ } | fl message > c:\errors.txt

For more information please follow link

Managing SharePoint Configuration

Saturday, 8 February 2014

View All Site collections in the Farm


  1. Verify that the user account that is performing this procedure is member of farm administrations SPGroup.
  2. On the central Administration Home Page, click on  Application Management
  3. On the Application Management page, in the site collections page, click view all site collections
  4. Select the web application in Web Application drop down for which you want to see the site collections
For More information follow link

Thursday, 21 November 2013

Number type input fields validation using JQuery

Using JQuery it is easy to validate numeric data in input fields.

Below code validates numeric input in the input type fields.
For this we only need to add .number as class for the input html tags in which we need to validate numeric data.

$('input.number').blur(function () {

    var value = $(this).val();

    if (value == undefined || value == "") {
        $(this).parent().find("span").remove();
        return;
    }
    if (isNaN(value)) {
        $(this).parent().find("span").remove();
        $(this).parent().find("br").remove();
        $(this).parent().append("</br><span class='error'>Please Enter Number</span>");
    }
});

Above blur event shows the Please Enter Number error message just after user moves cursor from input field.

Thursday, 14 November 2013

Creating SharePoint 2010 List Instances in Visual Studio 2010

We can easily create SharePoint 2010 List instances using visual studio 2010

Advantages:- 
  • If there is no need of custom list in any other SiteCollection other than in one site, it is no meaning to create list definitions. Instead we can create one list instance and deploy it to site directly.
  • After creating the new list instance we can add list data to Element file which will reduce the burden of creating list items every time that we deploy solution and even it will helps in the time of production site deployment.

Steps to Create:-
  1. In visual studio 2010 click on File -> New project then new project window will open.
  2. Then in Installed templates section of opened window select                     Visual C# ->SharePoint ->2010 -> then Empty SharePoint Project -> enter project name  -> then Ok - > Enter your site name and click on create. It will create project in visual studion.                                                                    
  3. After this in Solution Explorer Right click on your project then click on Add -> New item.
  4. Now in opened window select Online Templates -> List Instance and name your List then click on Add
  5. Now new List instance is added to your folder.

Sunday, 10 November 2013

SSRS 2008 R2 Export to Excel Hiding Columns

When I started working on SSRS in my learning days it took lot of my time to solve empty/hidden columns in excel after exporting from report.


Normally if you use only list control in your report without any other controls, we can export clean excel without any empty columns. But if there are any controls along with list control in your report, you have to concentrate more on alignment of each control to get proper excel export.

Hidden columns are result of small deviations in widths of controls.

For Example let us take one rectangle control for header and list control for users information in one Report as shown in Picture-1

Picture -1

Picture - 2






As shown in Picture 1, rectangle width is 1.0025 inches and list column width is 1.00 inches so because of 0.0025 difference in widths we will get column B as hidden in exported excel sheet as shown in Picture 2.

  • To avoid hidden columns maintain widths with rounded values.
  • If there are two or more controls above the list control, make sure each control is side by side and the width of each control is as integral multiple of list column width.

Saturday, 14 September 2013

Calling synchronous method asynchronously in .Net 3.5

  • We can call the methods asynchronously using custom  delegate that has an exact signature of method that you want to call asynchronously.
  • To know the completion status of the asynchronous method AsyncCallback delegate can be used.
      Below example illustrates the Asynchronous method execution.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AsyncDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            AsyncDemo ad = new AsyncDemo();

            AsyncDelegate asyncDelegate = new AsyncDelegate(ad.AsyncDelegate);

            AsyncCallback callback = new AsyncCallback(ad.Status);

            IAsyncResult result = asyncDelegate.BeginInvoke(callback, null);

            Console.WriteLine("Async method execution is running and status of completion is {0}", result.IsCompleted);
            Console.ReadLine();

        }
    }

    public delegate void AsyncDelegate();


    public class AsyncDemo
    {
        /// <summary>
        /// Method that executes asynchronously
        /// </summary>
        public void AsyncDelegate()
        {
            int a = 0;
            for (int i = 0; i < 2000000000; i++)
            {
                a += i;
            }
            Console.WriteLine("total  {0}", a);
        }

        /// <summary>
        /// Callback method that is invoked after the completion of async method execution
        /// </summary>
        /// <param name="result"></param>
        public void Status(IAsyncResult result)
        {
            Console.WriteLine("Async method execution is completed");
        }
    }
}



For more information follow the link http://msdn.microsoft.com/en-us//library/2e08f6yc.aspx

Saturday, 7 September 2013

How to read CSV file using FileHelperEngine


In below program File.csv contains the all the info of students.

"ReadAllText" static method of  File class is used to read all the csv file

then resulted string is passed as a parameter to ReadString instance method 

of FileHelperEngine class which returns the Student type array.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using FileHelpers;
using System.Configuration;
namespace My_console_app
{

    class Program
    {
        static void Main(string[] args)
        {
            string fileData = File.ReadAllText("C:\\File.csv");
            FileHelperEngine engine = new FileHelperEngine(typeof(Student));
            engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
            Student[] records = (Student[])engine.ReadString(fileData.Replace("\0", ""));
        }
    }

    [DelimitedRecord(",")]
    [IgnoreEmptyLines(true)]
    public class Student
    {
        [FieldQuoted('"', QuoteMode.OptionalForBoth)]
        public int Id;
        [FieldQuoted('"', QuoteMode.OptionalForBoth)]
        public string Name;
        [FieldQuoted('"', QuoteMode.OptionalForBoth)]
        public string Email;
    }

}


Here Student[] records contains all the students info as array.