Posts

Showing posts from 2014

How to automatically generate unique id in sql?

In sql there are many options to generate unique number. Here I am explaining about how to generate standard unique number in sql.

Below is sql query :

CREATE TABLE dbo.tblTable1
  (ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
   UserID AS UID + RIGHT(00000000 + CAST(ID AS VARCHAR(8)), 8) PERSISTED,
   username varchar(200),city varchar(200)
  )

State Management in C#

What is State Management in C#?State management tells how you store information over the lifetime of your application. This information can be a users name or shopping cart for an online shopping site.

Q. Why State Management is used ?
 Ans: We know all web page uses HTTP and HTTP is a stateless protocol. Means no state will be maintain on web page bu default.

2 Types of State Management-
-Client Side
-Server Side

Client Side State Management -

View State
One of the most common ways to store information is in view state. View state uses a hidden field that ASP.NET automatically insert when rendering page into HTML.
It’s a perfect place to store information that’s used for multiple postbacks in a single web page.

this.ViewState["Counter"] = 1;

Code that retrieves the counter from view state:
int counter;
counter = (int)this.ViewState["Counter"];

Cross Page Posting

Transferring or posting data from one page to another page is called cross page posting.

 protected voi…

what are differences between classic mode and claim based authentication in SharePoint 2010

what are differences between classic mode and claim based authentication in SharePoint 2010

Classic mode authentication: This is nothing but windows authentication. It means it will work based on you windows logged in credentials. There is a problem in classic mode authentication. Once a site is created under this authentication then Form based authentication can not be configured on the site.

Claim based authentication: Claim based authentication provides you a way to implement form based authentication as well as windows authentication. It is built on Security Assertion Markup Language (SAML) and Windows Identity Foundation.

How to work with features in SharePoint?

How to work with features in SharePoint? Feature deployment and activation in sharepoint

Feature is used to give some enhancement in SharePoint site.

Please follow below steps to use feature in SharePoint site.
Paste these two .xml files in below location.
C:\Program Files\Common Files\Microsoft Shared\webserver extensions\12\TEMPLATE\FEATURES\myfolder\
Here is both .xml files.

feature.xml (code)
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="5DFD12AF-D0AA-4c63-8FB8-C49DB1191083"
         Title="My Custom Action Feature"
         Description="Adds Custom Actions to the Web Site."
         Scope="Web"
         Version="1.0.0.0" >
<ElementManifests>      
<ElementManifest Location="element.xml"/>  
</ElementManifests>
</Feature>

element.xml(code)
<?xml version="1.0" encoding="utf-8" …

Introduction to WCF.

What is WCF? WCF stands for Windows Communication Foundation. The main use of WCF is to develop distributed system. WCF main feature is interoperability.

WCF tutorial for beginners and experience

WCF stands for Windows Communication foundation. It is used for developing distributed system.

Below are the topics which are important in WCF for beginners and for experience as well.

WCF Architecture

Image
WCF ArchitectureWCF stands for Windows Communication Foundation, introduced by Microsoft. WCF is one of the popular technology to build Service Oriented Systems. 

WCF vs Web Services

Most useful and most asked question in interview is WCF vs Web Services.
It could be asked in various form like Why WCF is better than Web Services

WCF and Web Services both are implementation of SOA (Service Oiented Architecture), both are SOAP based services.

Is it important to dispose an object in sharepoint ? what is the reason for poor performance.

Sharepoint foundation 2010 and sharepoint server 2010 object model contain objects that implement the IDisposable interface. Object disposal is very important in sharepoint.

Disposing Objects:

Sharepoint foundation 2010 and sharepoint server 2010 object model contain objects that implement the IDisposable interface.
You should explicitly dispose those sharepoint objects that implements IDisposable when you are finished using them.

Why to dispose?

SPSIte and SPWeb class objects are created as managed objects. However, these objects use unmanaged code and memory to perform their work. The manage part of the object is smaller than the unmanaged part.As smaller managed part does not put memory pressure, but large amount of unmanaged code can cause unusual behaviors.

So we should not rely on Garbage collector to release.
How to find incorrect Disposed objects--
--If system performs poor.

--If system crashes or user faces unexpected errors.

If your site is displaying unusual errors, there …

How to add an active class in navigation menu item in asp.net website?

How to add an active class in navigation menu item in asp.net website? Generally active class show which page /link you are visiting currently. Active class will be added in css class, but the problem is only one item can have active class at one time. But we need to show active class dynamically.

how to do url rewrite in C#.net. implemented in asp.net4.0 version

how to do url rewrite in C#.net. implemented in asp.net4.0 version

Url rewriting is just to display a friendly and readable url instead of a comlex or unfriendly url.

Suppose there is a url in your website just like below:

http://sharepointcafe.net/Page.aspx?userid=23456

The disadvantages of above mentioned url are:

1. This is not a friendly url.
2. The url does nt looks descent.
3. Last but the major thing is this url is not readable by Google and other search engine.

So, if your website contains url like above then there is no meaning of your content of that page because it will not be indexed by google.

So, how can it be avoid and how it can be re write in a seo friendly and readable url.

In asp.net 3.0 it was not an easy task to complete. But in asp.net4.0 it is very easy.

I am explaining this for asp.net 4.0 version.

First add a Global.asax file in your project.

Add the reference of System.Web.Routing in your project.
And then add this <%@ Import Namespace="System.Web.Ro…

Three tier architecture in ASP.Net using C# code

Image
3-Tier architecture is well known in software development for web and windows software.
3-Tier architecture contains UI (Presentation) Layer, Business Logic and Data Access Layer.

In below structure you can see- Program.cs is Presentation Layer (i.e. for User Input) BAL.cs - Business Logic, BO.cs - Business Entity DAL.cs - Data Access Layer

Lets see code one by one for 3 tier architecture.
Program.cs
namespace Practice {     class Program     {         static void Main(string[] args)         {             Program objP = new Program();             objP.InsertRecordFunction();             objP.PrintData();         }         private void PrintData()         {             Practice.BAL objBusinessLayer = new BAL();             objBusinessLayer.GetEmployeeRecord();         }         private void InsertRecordFunction()         {             BO objBusinessEntity = new BO();
            Console.WriteLine("Enter Login");             objBusinessEntity.Login = Console.ReadLine();
            Console.WriteLi…

How to send email to a user using workflow in SharePoint2010

How to send email to a user using workflow in SharePoint2010

Suppose there is a scenario that when ever you add a new item to a list in SharePoint site immediately an email should be sent to a specific member or user.
Here I will explain this scenario by using SharePoint designer 2010.
Please follow below steps:
1. Open SharePoint site in SharePoint designer. 2. File-New-Workflow  3. Once the dialog box opened then Enter the name of workflow and then select sharepoint list or library on which you want your workflow to be execute. and click Next. 5. Dont forget to select workflow start option, i.e. whether you want it to be started automatically or manually. 5. From Actions select send an Email. 6. Now click on this message, in the action that appears now. 7. Now in the new dialog box, enter the user email id in To box. 8. Then type a subject in subject box. 9. Now click OK.
Now, you can test your workflow by adding an item in list.

Can we implement interface with same method name?

Interface is similar to a class, and we implement interface by defining their method in class. Suppose we have same method in more than one interface.

In this case there will be a question for interview.

Q.    Can we implement interface with same method name?
Ans. Yes by using explicit interface implementation.

Lets see below example:

class Program
    {
        static void Main(string[] args)
        {
            MyInterface1 obj1 = new MyClass();
            MyInterface2 obj2 = new MyClass();

            obj1.func1();
            obj2.func1();
        }
        interface MyInterface1
        {
            void func1();
        }

        interface MyInterface2
        {
            void func1();
        }

        class MyClass : MyInterface1, MyInterface2
        {
            void  MyInterface1.func1()
            {
                Console.WriteLine("Hello1");
            }

            void MyInterface2.func1()
            {
                Console.WriteLine("Hello2");
            }
      …

What is safe control in SharePoint 2010?

In SharePoint Environment a developer can add ASPX file very easily. An ASPX file contains code which may affect SharePoint environment. In simple word, there might be security risk of security injection.

To reduce the risk, SharePoint differentiate the assembly which need to protect against script injection. This can be done by marking a control as "Safe Control" in SharePoint web.config file.

Code snippet of Safe Control:

SharePoint>
     <SafeControls>
       <SafeControl Assembly="[Assembly Name]" Namespace="[Namespace]" TypeName="*" Safe="True" />
     </SafeControls>
</SharePoint>


To mark controls as safe or unsafe in the Package Designer
Create a SharePoint solution with a Visual Web Part project.Add two controls to the Web part: a text box and a button. Leave the names at their default values, TextBox1 and Button1, respectively.Take note of the namespace of the control because it is used later.On the menu …

How to create a batch file to do automatic backup of SharePoint site?

Suppose you have a SharePoint site with some heavy and important data and you want to take the backup regularly. So instead of manual process you can create a batch file which will automatically take the backup of the mentioned site.

Below is the given script:
Write below code in a notepad and save it as .bat file.

@echo off
@echo
@echo This script will backup your site: [Enterprise Management Site]
@echo
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
@echo locking site collection before the backup process starts
@echo off

stsadm -o getsitelock -url http://moss-server:333/
stsadm -o setsitelock -url http://moss-server:333/  -lock readonly
@echo site collection is now locked
@echo off
stsadm -o backup -url http://moss-server:333/  -filename C:\RRSbackup\autobackup.bak -overwrite @echo backup completed
@echo off
stsadm -o setsitelock -url http://moss-server:333/  -lock none
@echo Site lock removed

Once you ready with your batch file then you can put this…