Access Denied Error while Cross Domain Communication with File upload control Internet explorer (ie)

Ok its quite tested by me that if you doing cross domain communication and raising event with file input control then it wont get uploaded. You will receive Access Denied error. So just use input control as is, no event generation from other control like $(“a”).Click(function(){$(“#file”).click()}) will work with ie. but if you using FF or Chrome than it will work fine.

Posted in Uncategorized | Tagged , , , , | Leave a comment

Solving mysteries: Facebook Share functionality

Following are few fix for Facebook share functionality

Symptoms : No image or thumbnail image is shared on wall
1. Add “image_ref” tag on top, now they are proposing to use “og:image”.

2. Facebook cache the images once you shared with them, so if you think that you changed image and it is not appearing than don’t worry try using “Linter” it will clear the cache if you are fortunate or else your fate is in hand of Facebook Bot(it will take time to get page crawled again).

3. Ohh. have you checked the size of image, which you are sharing on facebook? it should be more than 50px of height.

Posted in Facebook | Tagged , , , , , , , | Leave a comment

For Loop – worst case performance – Big O notation – o(n)

Recently I came across one of many Big O notations ,O(N), which means “that for large enough input sizes the running time increases linearly with the size of the input – wikipedia”.

In other words if i want to search one value from array by iterating each element than the “worst case scenario” would be to get desired value at last position. so, I have to iterate array.length times to search desired item. below for loop does same,

For i=0 to array.length -2
If(array[i] = 1)
return true;
In above example we can’t guarantee that at which place “array” may contain “1” or it doesn’t contain.

In algorithmic terms it is called as “Linear Time” or O(n) time.

So no one want to face such scenario, than there are many algorithms present today for the solution like,
Binary Search and its variations. At the ends it is upto developer that how he sees the scenario and implement the solution.

Further reading from here,

Posted in Algorithms | Tagged , , , | Leave a comment

Application Design

Many times I read the questions posted on online forums that “How should be my application design”,”Where to put entities”, “Which is the best place to put POCO classes”, “Where to put EF generated entities”, sometimes like “I am building nTier application and can you help me to place my context, entities and/or model” (sometimes questions posted with MVC tag). And people answered them very well too, but still my two cents on this topic,

So in my opinion people should read the “Domain Driven Design-Eric Evans” which helped me lot to understand the layering of the application, writing code with Domain in mind.

Layering of the application is very important part of the project design and if this part is not designed well than often you will learn words “Code Smell”, “Fatty Classes” etc. So be cautioner while design the application, give good amount of time to design it.

So how should be the good design and the answer is “it depends”, but my design should,

– Accommodate new changes, at the same time it should follow the legendary Open Close Principle.
– Pluggable Architecture with Separation of concerns, means the libraries which we build, should be plugged into another application (With MVC, WPF, Win App, WCF).
– And finally developer should DRY(Don’t Repeat Yourself). That means whatever code you have written, it should be reusable. I know most of the time it doesn’t happen but still, one should think before writing “how this piece of code can be reusable”.

To reduce Developer task,
– While making an application, should use tools like T4 templates which gives us ready made code(CRUD or Creation of Master Forms) for similar kind of modules, it will save the time of writing and testing it.
– Tools like Automapper which copies one object to another. e.g. Copying Entity to POCO or vice versa.

Posted in Application Design | Tagged , , , , , | Leave a comment

Adding custom query to typed dataset

Below code will work if you working with typed dataset and you want to execute your own queries against adapters i.e. custom queries with typed dataset.

So you have to utilize the partial class of adapters.

namespace MyWin.DataSet1TableAdapters //partial class to add my custom method to update the command collection and queries.

public partial class EmpTableAdapter
public void fillformyquery(MyWin.DataSet1.EmpDataTable emp1)
System.Data.OleDb.OleDbCommand[] mycol = new System.Data.OleDb.OleDbCommand[1];

mycol[0] = new global::System.Data.OleDb.OleDbCommand();
mycol[0].Connection = this.Connection;
mycol[0].CommandText = “Select * from emp where name = ‘%alliswell%'”;
mycol[0].CommandType = global::System.Data.CommandType.Text;
this._commandCollection = mycol;

//this._commandCollection = new System.Data.OleDb.OleDbCommand[1];

//calling code

public void RunMyQuery()
dataset1.EmpTableAdapter eda = new dataset1.EmpTableAdapter();//assume you have added adapter to the designeer
dataset1.EmpDataTable emp1 = new dataset1.EmpDataTable();


Posted in Uncategorized | Tagged , , , , , | Leave a comment

Custom Attribute to Validate Duplicate Entity

This post is for Duplicate Entity check using C# Attributes,(Based on the question which I recently answered)

If you want to check whether any entity present in database or not, so this can be achieved using Custom Attribute which is mentioned below,

I put this as a Class level attribute but you can extend it and make it for Property levels also.

Attribute Class code as goes..
public class DuplicateUserAttribute : ValidationAttribute
private const string _defaultErrorMessage = “user ‘{0}’ Already exist”;

public DuplicateUserAttribute ()
: base(_defaultErrorMessage)

public override string FormatErrorMessage(string name)
return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString);


public override bool IsValid(object value)
UserEntity NewUser = value as UserEntity;
//Write here logic to validate the user is already exist in database like
context.UserList.Where(u=>u.Name ==NewUser .UserName)
return ;

Now you can use simply,
Class User


You need give reference of System.ComponentModel.DataAnnotations.dll.
In System.ComponentModel.DataAnnotations.dll you can find many predefined attributes also like, RequiredAttribute, DataTypeAttribute.

Posted in Uncategorized | Tagged , , , , , , , , , , | 1 Comment