473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GetObject in .NET c#

Dear All,

I have to move my VB code to C#. But I have no idea on the GetObject method
in Vb.

-----------------------------------------
Set dom = GetObject("WinNT://" & domain)
-----------------------------------------

This is easy for VB to get the object by COM monikor interface.

However, what I use the following code to active a object via monikor in c#,
what I got is a OBJECT Type.
----------------------------------------------
Marshal.BindToMoniker("WinNT://" + strDomain); //c# code
----------------------------------------------

Is there any way for me to KNOW the returned object type and case it to the
right type in .net???
Thanks very much!

-yy
Nov 15 '05 #1
5 6095
You shouldn't do this in .NET, the System.DirecotoryServices namespace
contains the classes you are looking for to access the WinNT provider
intetrface.

Willy.

"Yong Yu" <yy@yuyong.net> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Dear All,

I have to move my VB code to C#. But I have no idea on the GetObject method in Vb.

-----------------------------------------
Set dom = GetObject("WinNT://" & domain)
-----------------------------------------

This is easy for VB to get the object by COM monikor interface.

However, what I use the following code to active a object via monikor in c#, what I got is a OBJECT Type.
----------------------------------------------
Marshal.BindToMoniker("WinNT://" + strDomain); //c# code
----------------------------------------------

Is there any way for me to KNOW the returned object type and case it to the right type in .net???
Thanks very much!

-yy

Nov 15 '05 #2
Thanks!

I know there is a DirecotoryServices in .net. However, my task is to create
NT user and mailbox, create and update the Exchagne 5.5 Distributed List.
All this requirement have detailed sample in ADSI 2.5 SDK.

I just donot like VB:-) And I want to know how to get the type of a
late-bind interface in .net

thanks very much!

- yy
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl...
You shouldn't do this in .NET, the System.DirecotoryServices namespace
contains the classes you are looking for to access the WinNT provider
intetrface.

Willy.

"Yong Yu" <yy@yuyong.net> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Dear All,

I have to move my VB code to C#. But I have no idea on the GetObject

method
in Vb.

-----------------------------------------
Set dom = GetObject("WinNT://" & domain)
-----------------------------------------

This is easy for VB to get the object by COM monikor interface.

However, what I use the following code to active a object via monikor in

c#,
what I got is a OBJECT Type.
----------------------------------------------
Marshal.BindToMoniker("WinNT://" + strDomain); //c# code
----------------------------------------------

Is there any way for me to KNOW the returned object type and case it to

the
right type in .net???
Thanks very much!

-yy


Nov 15 '05 #3
Did you actualy read the docs /samples in msdn?.
The DirectoryServices namespace classes are simple wrappers around ADSI, so
everything what can be done with ADSI can be done using these classes.
ADSI exposes a set of COM interfaces to be consumed by COM clients, the
DirectoryServices classes expose these COM interfaces as .NET managed
classes. When using managed tools like C# you should use the managed classes
(where available) and stay away from COM interop in your code.

Willy.
"Yong Yu" <yy@yuyong.net> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
Thanks!

I know there is a DirecotoryServices in .net. However, my task is to create NT user and mailbox, create and update the Exchagne 5.5 Distributed List.
All this requirement have detailed sample in ADSI 2.5 SDK.

I just donot like VB:-) And I want to know how to get the type of a
late-bind interface in .net

thanks very much!

- yy
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl...
You shouldn't do this in .NET, the System.DirecotoryServices namespace
contains the classes you are looking for to access the WinNT provider
intetrface.

Willy.

"Yong Yu" <yy@yuyong.net> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Dear All,

I have to move my VB code to C#. But I have no idea on the GetObject

method
in Vb.

-----------------------------------------
Set dom = GetObject("WinNT://" & domain)
-----------------------------------------

This is easy for VB to get the object by COM monikor interface.

However, what I use the following code to active a object via monikor
in c#,
what I got is a OBJECT Type.
----------------------------------------------
Marshal.BindToMoniker("WinNT://" + strDomain); //c# code
----------------------------------------------

Is there any way for me to KNOW the returned object type and case it
to the
right type in .net???
Thanks very much!

-yy



Nov 15 '05 #4

"Yong Yu" <yy@yuyong.net> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...

I just donot like VB:-) And I want to know how to get the type of a
late-bind interface in .net


Too bad you don't like VB, because C# doesn't support late binding (and I'm
not just talking about ADSI calls).
In order to deal with late binding, you need to go through the cumbersome
steps of reflection/invokation.
Also note that binding has nothing to do with object creation. In other
words, the use of a function like GetObject does not mean you are
late-binding to an instance.
Invoking members on an object with a type that is unknown until runtime is
late-binding. You can use a function like GetObject with a specificly-typed
reference, and you are early-binding to the instance.
Getting back on track, like the others are pointing out, you should
certainly use the Directory Services classes in .NET (whether you are in VB
or C#).

-Rob Teixeira [MVP]
Nov 15 '05 #5
Rob Thanks for your input!

I got this for the late binding
================================================== ==========================
==
object objValue =
Marshal.BindToMoniker(LDAP://OU=OUName,DC=DomainName,DC=com);
Type type = objValue.GetType();
string name = (string)type.InvokeMember("Name",
BindingFlags.Instance | BindingFlags.Public |
BindingFlags.GetProperty,
null,
objValue,
null,
null,
null,
null);
Console.WriteLine(name);
================================================== ==========================
==

BTW, I will goto use the .NET DS, thank you Willy!

- yy
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Yong Yu" <yy@yuyong.net> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...

I just donot like VB:-) And I want to know how to get the type of a
late-bind interface in .net

Too bad you don't like VB, because C# doesn't support late binding (and

I'm not just talking about ADSI calls).
In order to deal with late binding, you need to go through the cumbersome
steps of reflection/invokation.
Also note that binding has nothing to do with object creation. In other
words, the use of a function like GetObject does not mean you are
late-binding to an instance.
Invoking members on an object with a type that is unknown until runtime is
late-binding. You can use a function like GetObject with a specificly-typed reference, and you are early-binding to the instance.
Getting back on track, like the others are pointing out, you should
certainly use the Directory Services classes in .NET (whether you are in VB or C#).

-Rob Teixeira [MVP]

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Rich | last post by:
Hello, I have not been working with ASP for too long at this time and am not real familiar with a lot of things about ASP. I have searched for articles on the following question but not come up...
2
by: CJM | last post by:
I'm building an ASP app that uses Windows Authentication (IWA). I have an authentication routine that assesses if & how the user can use the application (see code snippet below). Users of a...
5
by: Andrei | last post by:
Hello, I posted yesterday the same problem, but now I want to be more specific about it. My intention is to create a windows service to process some Word documents. If I use CreateObject to...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
1
by: Martyn Gwynne | last post by:
I am progressing with GetObject .. The following code will open and print a report. I enquired how to open, maximise WITHOUT printing by default and it was suggested that I look at further...
2
by: Randy Harris | last post by:
I'm going nuts trying to figure this out, sure hope someone can help. My application uses TransferSpreadsheet to insert data into an existing Excel spreadsheet (which works), then opens and...
17
by: ad | last post by:
We can use GetObject to load the instance of COM form file like: Dim CADObject As Object CADObject = GetObject("C:\CAD\SCHEMA.CAD") How can we implement the two statements above in CSharp?
3
by: perspolis | last post by:
Is there a method like GetObject in vb to get an instance of current object runnig??
3
by: ]-[aTc]-[ | last post by:
I'm trying to add users to active directing using asp.net forms. All the example on the web are for VB and using the VB method GetObject. Is there a C# sharp equivalent of GetObject or can...
1
by: joe | last post by:
We just moved a legacy asp application to a Win2003 server. The following line of code: set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName & ",user") Raises the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.