Friday 14 October 2011

Windows User Account Control (UAC) restrictions have been addressed

When you are working with the SQL Server Reporting services on windows server 2008 R2 and Window7 then you may encounter the following exception

User ‘Domain\User’ does not have required permissions. Verify that sufficient permissions have been granted and Windows User Account Control (UAC) restrictions have been addressed


To overcome that issue we nee to set the User Account Control settings. The steps to set the User Access Control as follows

  1. Open control panel
  2. Click on System and Security
  3. Click on User Account Control Settings

    4.  Slide down the User Account Control up to never notify. Then Click on Ok.

   5. Restart the system now.
   6. Open the Report server url in browser(Ex: http://systemname/Reports)

I hope this will helps to you.



Replacing special characters while creating directory or file

When we are creating directory in windows it could not accept the spacial character for directory name.
If folder name string is dynamic( we don't know which string it is) then we need to write the spacial character from that string. To repalce special characrers while creating directory as follows(this step must be added if we don't confirm that string)
directoryname=System.Text.RegularExpressions.Regex.Replace(directoryname,@"[*?:\|<>\\/]", "-");

Monday 3 October 2011

How to get comma separated string from the list of object for specified property

I have a one requirement that I have list of objects with that object have properties(ID, Name, Description). I want a comma separated string from the list of object for ID property.
We can achieve this by using Reflection classes.

The solution for the requirement has follows

Create a generic method to get the Comma separated string
 public static string GetCommaSeparatedString<T>(List<T> list, string property)
        {
                string value = string.Empty;
                PropertyInfo info = typeof(T).GetProperties().Where(i => i.Name == property).FirstOrDefault();
                if (info != null)
                {
                    foreach (T listItem in list)
                    {
                        value += info.GetValue(listItem, null).ToString() + ",";
                    }
                }
            return value.Substring(0,value.Length-1);
        }
Usage:
Take an example with Category class with the properties ID,Name
public class Category
{      
    public int ID { get; set; }
    public string Name { get; set; }
}
Create a list with Category objects
List<category> categories=new List<category>();
categories.Add(new Catagory {ID=1, Name = "abc" });
categories.Add(new Catagory {ID=10, Name = "pqr" });
Call the method as follows
GetCommaSeparatedString<Category>(categories,"ID");
//output: 1,10