02 August 2010

How to get User Details from Active Directory of a domain by using Shapoint 2010 web part or Asp.net ?????

Hi All .......!!!!!

I am working under a project that is related to client server Architecture. So I had to load username to my web page so I had to create web Application...

First of all ...,

I have created ASP.net web Application. Ok I Will Explain how to do it in step by step...



Step 01

Go to Start Visual Studio 2008. In the welcome window click new > Project

Then New Project pop up window will appear Click on following sequence.

Visual C# > web then select Asp.net Web Application. In the name field give a suitable Name and give location you want and click OK





Now you can see Following coding window.



Step 02


Now click on design button in your default.aspx tab and Drag and Drop a Label and command button. Basically we are going to do load user names and to web page and take selected user by clicking command button.




Step 03


Double click on command button and write following code inside the coding window. Dont forget to add System.DirectoryService reference into you code window.Here I am using User_Names linked list and RadioButton list. Ok I am explaning about Radio button list later.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.DirectoryServices;
using System.Data;

namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
RadioButton button = new RadioButton();
List rbutton = new List();
List User_Names = new List();
public DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
string domain = "LDAP://sharepointsvr";
DirectoryEntry entry = new DirectoryEntry(domain);

DirectorySearcher searcher = new DirectorySearcher(entry);

searcher.Filter = "(&(objectClass=user))";

SearchResultCollection resultCol = searcher.FindAll();

int count = 0;
foreach (SearchResult result in resultCol)
{
User_Names.Add(result.Properties["CN"][0].ToString());
count = count + 1;
}

if(!IsPostBack)
{
RadioButtonList1.DataSource = User_Names;
RadioButtonList1.DataBind();
}
}




Step 04

Write down following code inside the button click method of your command button.


protected void Button1_Click(object sender, EventArgs e)
{

Label2.Text = RadioButtonList1.SelectedItem.Text;

}

I told you i want to add Radio Bitton list into my web page
Now I am trying to add radio button list. Here we go

click on default.aspx tab and click on code .Now wtite down following code soon after the button code.


asp:radiobuttonlist id="RadioButtonList1" runat="server" autopostback="true" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" enableviewstate="true"



Note that :
above should be inside <> signs and /asp:RadioButtonList this code part should be inside the <> signs

Step 05

Now Save it and build it


ඉතුරු ටිකත් කියවන්න...