Showing posts with label directory. Show all posts
Showing posts with label directory. Show all posts

Thursday, March 29, 2012

object records set HELP??

hello friends I am using actice directory as my data source through LDAP to get the usernam/password, and thn after authantication i use LDAP to get the user information (username, name, phone, email, location etc from active directory user profiles)

As u can see in the code i am using the loop to write the information on the page using

Response. write

I wan't to use some other data control to make the output more redable, like Repeater.

Sub getdetails()Dim objCommand, objConnection, strBase, strFilter, strAttributes'Declare the variables as stringDim strQuery, objRecordset, strName, strCN, strCompany, strOfficeLocation, strDept, strJobtitle, strStreetAddress, strCounty, strPostalcode, strPhone, strMail

objCommand = CreateObject(

"ADODB.Command")

objConnection = CreateObject(

"ADODB.Connection")

objConnection.Provider =

"ADsDSOObject"

objConnection.Open(

"Active Directory Provider")

objCommand.ActiveConnection = objConnection

'Define the Search Base, Filter and Attributes

strBase =

"<LDAP://dc=ESPRIT,dc=local>"

strFilter =

"(&(objectCategory=person)(objectClass=user)(sAMAccountName=" +Me.lbl_welcome.Text +"))"'database field name are same as in AD

strAttributes =

"sAMAccountName,cn,company,l,department,title,streetAddress,st,postalCode,telephonenumber,mail"'Subtree is the default base

strQuery = strBase &

";" & strFilter &";" & strAttributes &";subtree"

objCommand.CommandText = strQuery

'objCommand.Properties("Page Size") = 100'objCommand.Properties("Timeout") = 30' objectCommand_Properties(cache Results) if set to False gives some error so keep it True always

objCommand.Properties(

"Cache Results") =True

objRecordset = objCommand.Execute

'Pick the values of the fields in string variablesDoUntil objRecordset.EOF'Search the whole database Record till EOF and put the field value in the string variable and write it to the document(page)

strName = objRecordset.Fields(

"sAMAccountName").Value

strCN = objRecordset.Fields(

"cn").value

strCompany = objRecordset.Fields(

"company").value

strOfficeLocation = objRecordset.Fields(

"l").value

strDept = objRecordset.Fields(

"department").value

strJobtitle = objRecordset.Fields(

"title").value

strStreetAddress = objRecordset.Fields(

"streetAddress").value

strCounty = objRecordset.Fields(

"st").value

strPostalcode = objRecordset.Fields(

"postalCode").value

strPhone = objRecordset.Fields(

"telephonenumber").value

strMail = objRecordset.Fields(

"mail").value

Response.Write(

"User Name: " & strName &" Common Name: " & strCN &" Company Name: " & strCompany &" Office/Branch " & strOfficeLocation &" Department Name: " & strDept &" Job Title: " & strJobtitle &" Full Address: " & strStreetAddress &" County: " & strCounty &" Postal Code: " & strPostalcode &" Phone: " & strPhone &" Email: " & strMail)

objRecordset.MoveNext()

Loop

objConnection.Close()

'Connection ClosedEndSub

I am using object recordset for this. can anybdy suggest me how i can use some other datacontrol with this coding.

Thanks

You mentioned you wanted to use a repeater which is an ASP.NET control, but your code looks like Classic ASP. What are you using ASP.NET or Classic ASP?

Monday, March 26, 2012

Object reference not set to an instance of an object

here is my code.. i am trying to get the zipcode information from an active directory server

<%
Dim entry As New DirectoryServices.DirectoryEntry("LDAP://schpdc")
Dim Dsearch As New DirectoryServices.DirectorySearcher(entry)
Dim zip As String
Dim UserName As String
Dim testname As String
zip = "error"
UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split("\")(1)
Response.Write(UserName & "<br>")
Dsearch.Filter = "(cn=" + UserName + ")"
Response.Write(Dsearch.Filter)
Try
zip = Dsearch.FindOne.Properties("zipcode").ToString()
Catch E As Exception
zip = "Error: " & E.Message
End Try
Response.Write(zip)
%>

please help.. i am now just spinning my wheels!!!

Which line is throwing the error?


To be honest i am not sure what is causing the error.. however i am pretty sure it is in the try statement as that is what actually writes it out and it always runs the catch. (sorry for the delay in reply.. i was sick yesterday)


Put breakPoint to debud the error. Usually, the error happened in Name.Split("\")(1) or Properties("zipcode").ToString(). Because you already put try.. catch for Properties("zipcode").ToString(), I am afraid the error was caused by Name.Split("\")(1).


i dont think that is the case.. i added a line to make the username = to the full return (instead of the split return) here is what i get

FORTITECH\intranet
intranet
(& (objectClass=user)(cn=intranet))Error: Object reference not set to an instance of an object.

the first line is the return unsplit user name... the second is the split user name (the user whos AD values i want returned)

line 3 is split a little all return within the () is the Dsearch.Filter and everything after is from the try statement (the catch side of course).


You know Try..Catch, right? Therefore, the error should happen before TRY. Put breakpoint at the line before Try, then debug it step by step, you should be easy to find which line caused the error.


this will probably sound incredibly stupid but i am working on a dotnetnuke module and can not find anyway to run this outside of a web browser. web developer 05 allows me to add breakpoints but will not let me run the code independently...


Try to comment out line one by one. Start from Response.Write(Dsearch.Filter). You will find the line that causes the error.

if i dont declare a dsearch.filter i get the following

(objectClass=*)Error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

it looks as though either this line isnt pulling the right row...

Dsearch.Filter = "(& (objectClass=user)(cn=" + UserName + "))"

or this line isnt referring to a proper column

Dsearch.FindOne.Properties("postalCode")(0).ToString()

do you know a way to return the entire row? if so i could narrow it down to the first line... hopefully


I did Active Directory project long time before, I had some code as following:

search.Filter = "(SAMAccountName=" + userName + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];

Please search Active Directory and ASP.NET online to find helps.


could you walk me through this please?


Did you check to make sure zip code in AD called "ZipCode"? I though it called "postalCode".


Also, here is the forum on Active Directory. Please search your issue here.

http://forums.asp.net/93.aspx


i have tried both. neither seemed to work as a direct replacement.


che3358:

Did you check to make sure zip code in AD called "ZipCode"? I though it called "postalCode".

Do you know what the login name property is called within active directory?

Thursday, March 22, 2012

Object reference not set to an instance of an object.

Hi Everyone,

It has been a long time. Anyhow, I am writing this app that is suppose to
access a directory on the server and list all the directories files and bind
it to a Repeater control. This is the source or codebehind rather:

private void Page_Load(Object source, EventArgs e)
{
If(!Page.IsPostBack)
{
...
showDirectoryContents(Server.MapPath(Directory Path));
...
}
}
private void showDirectoryContents(string Path)
{
DirectoryInfo dir=new DirectoryInfo(Path);
FileInfo[] fileCollection=dir.GetFiles();
Repeater1.DataSource=fileCollection;
Repeater1.DataBind();
}
The error I am getting is as follows:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 210:DirectoryInfo dir=new DirectoryInfo(Path);
Line 211:FileInfo[] fileCollection=dir.GetFiles();
Line 212:Repeater1.DataSource=fileCollection; <--this line is the
source of the problem.
Line 213:Repeater1.DataBind();
Line 214:}

I've scripted the repeater control into the form as it should be and set the
id to Repeater1 so I don't know what I'm doing wrong. Can someone tell me
what I'm missing here?

Thank you.

Sam-Hi,

I am Sam wrote:

Quote:

Originally Posted by

Hi Everyone,
>
It has been a long time. Anyhow, I am writing this app that is suppose to
access a directory on the server and list all the directories files and bind
it to a Repeater control. This is the source or codebehind rather:


Do you have a aspx.designer.cs file under the ASPX file in the Solution
explorer? Sometimes (especially when porting a 1.1 application to 2.0),
the file is not generated automatically, and then the controls are not
created.

Two ways around that: Declare the "Repeater1" yourself in the code
behind (must be protected), or recreate the ASPX file, copy-paste the
controls inside it, compile and make sure that the designer.cs file is
generated correctly this time.

HTH,
Laurent

Quote:

Originally Posted by

private void Page_Load(Object source, EventArgs e)
{
If(!Page.IsPostBack)
{
...
showDirectoryContents(Server.MapPath(Directory Path));
...
}
}
private void showDirectoryContents(string Path)
{
DirectoryInfo dir=new DirectoryInfo(Path);
FileInfo[] fileCollection=dir.GetFiles();
Repeater1.DataSource=fileCollection;
Repeater1.DataBind();
}
The error I am getting is as follows:
>
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
>
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
>
Source Error:
>
>
Line 210:DirectoryInfo dir=new DirectoryInfo(Path);
Line 211:FileInfo[] fileCollection=dir.GetFiles();
Line 212:Repeater1.DataSource=fileCollection; <--this line is the
source of the problem.
Line 213:Repeater1.DataBind();
Line 214:}
>
I've scripted the repeater control into the form as it should be and set the
id to Repeater1 so I don't know what I'm doing wrong. Can someone tell me
what I'm missing here?
>
Thank you.
>
Sam-


--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Friday, March 16, 2012

Object reference not set to an instance of an object.

Hi Everyone,
It has been a long time. Anyhow, I am writing this app that is suppose to
access a directory on the server and list all the directories files and bind
it to a Repeater control. This is the source or codebehind rather:
private void Page_Load(Object source, EventArgs e)
{
If(!Page.IsPostBack)
{
..
showDirectoryContents(Server.MapPath(Directory Path));
..
}
}
private void showDirectoryContents(string Path)
{
DirectoryInfo dir=new DirectoryInfo(Path);
FileInfo[] fileCollection=dir.GetFiles();
Repeater1.DataSource=fileCollection;
Repeater1.DataBind();
}
The error I am getting is as follows:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information abou
t
the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 210: DirectoryInfo dir=new DirectoryInfo(Path);
Line 211: FileInfo[] fileCollection=dir.GetFiles();
Line 212: Repeater1.DataSource=fileCollection; <--this line is the
source of the problem.
Line 213: Repeater1.DataBind();
Line 214: }
I've scripted the repeater control into the form as it should be and set the
id to Repeater1 so I don't know what I'm doing wrong. Can someone tell me
what I'm missing here?
Thank you.
Sam-Hi,
I am Sam wrote:
> Hi Everyone,
> It has been a long time. Anyhow, I am writing this app that is suppose to
> access a directory on the server and list all the directories files and bi
nd
> it to a Repeater control. This is the source or codebehind rather:
Do you have a aspx.designer.cs file under the ASPX file in the Solution
explorer? Sometimes (especially when porting a 1.1 application to 2.0),
the file is not generated automatically, and then the controls are not
created.
Two ways around that: Declare the "Repeater1" yourself in the code
behind (must be protected), or recreate the ASPX file, copy-paste the
controls inside it, compile and make sure that the designer.cs file is
generated correctly this time.
HTH,
Laurent

> private void Page_Load(Object source, EventArgs e)
> {
> If(!Page.IsPostBack)
> {
> ...
> showDirectoryContents(Server.MapPath(Directory Path));
> ...
> }
> }
> private void showDirectoryContents(string Path)
> {
> DirectoryInfo dir=new DirectoryInfo(Path);
> FileInfo[] fileCollection=dir.GetFiles();
> Repeater1.DataSource=fileCollection;
> Repeater1.DataBind();
> }
> The error I am getting is as follows:
> Object reference not set to an instance of an object.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information ab
out
> the error and where it originated in the code.
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
> Source Error:
>
> Line 210: DirectoryInfo dir=new DirectoryInfo(Path);
> Line 211: FileInfo[] fileCollection=dir.GetFiles();
> Line 212: Repeater1.DataSource=fileCollection; <--this line is the
> source of the problem.
> Line 213: Repeater1.DataBind();
> Line 214: }
> I've scripted the repeater control into the form as it should be and set t
he
> id to Repeater1 so I don't know what I'm doing wrong. Can someone tell me
> what I'm missing here?
> Thank you.
> Sam-
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch