|
I have the following method to retrieve user details from Active Directory.
public StringCollection getUserDetails(string user)
{
StringCollection coll = new StringCollection();
try
{
DirectorySearcher search = new DirectorySearcher(obEntry);
search.Filter = "(SAMAccountName=" + user + ")";
search.PropertiesToLoad.Add("Name");
search.PropertiesToLoad.Add("displayName");
SearchResult result = search.FindOne();
if( result != null )
{
DirectoryEntry dirEntry = result.GetDirectoryEntry();
foreach(string key in dirEntry.Properties.PropertyNames)
{
// Each property contains a collection of its own
// that may contain multiple values
foreach( object propVal in dirEntry.Properties[key] )
{
string[] Names = {key + "=" + propVal};
coll.AddRange(Names);
}
}
}
return coll;
}
catch( Exception ex )
{
throw new Exception("User not authenticated: " + ex.Message);
}
}
All my output is returned into a stringcollection as shown below.
<string>givenName=Reinier
<string>homeDrive=M:
<string>instanceType=4
<string>lastLogoff=System.__ComObject
<string>lastLogon=System.__ComObject
The problem i have is that some values are returned as System.__ComObject. I would like to see the value there too. Is there a way to iterate through System.__ComObject and return it's values(s) ? Somewhere i have to check propVal for it's type and read out the values if type is System.__ComObject ??
Hope someone can put me on the right track !
|
|
|
|
|
The date properties are returned via the IADsLargeInteger[^] interface, which doesn't seem to have been included in the .NET framework. You will need to manually import it to get the data:
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
public sealed class AdsiUtils
{
private AdsiUtils() {}
[
ComImport,
Guid("9068270b-0939-11d1-8be1-00c04fd8d503"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)
]
private interface IADsLargeInteger
{
[DispId(2)] int HighPart { get; set; }
[DispId(3)] int LowPart { get; set; }
}
public static DateTime AdsDateValue(object value)
{
try
{
IADsLargeInteger v = value as IADsLargeInteger;
if (null == v) return DateTime.MinValue;
long dV = ((long)v.HighPart << 32) + (long)v.LowPart;
return DateTime.FromFileTime(dV);
}
catch
{
return DateTime.MinValue;
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi Richard, thanks for your answer although i'm not there yet. I added the code to my class and get this message while compiling:
C:\Inetpub\wwwroot\ADSI\ADSI.cs(54): The type or namespace name 'IAdsLargeInteger' could not be found (are you missing a using directive or an assembly reference?)
C:\Inetpub\wwwroot\ADSI\ADSI.cs(55): The name 'v' does not exist in the class or namespace 'ADSI.ADSI'
C:\Inetpub\wwwroot\ADSI\ADSI.cs(56): The type or namespace name 'v' could not be found (are you missing a using directive or an assembly reference?)
Any idea what i'm missing here ?
|
|
|
|
|
Sorry - there was a typo in the code!
Change the first line within the try block to:
IADsLargeInteger v = value as IADsLargeInteger;
I've modified the original post to show the correct code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
wow, works great ! this great, thanks a lot Richard !
got one more question though I also have types like these
objectGUID = System.Byte[]
objectSid = System.Byte[]
Would you happen to know how to read data form System.Byte[] ?
|
|
|
|
|
The objectGUID is simple - just call:
Guid objectGuid = new Guid((byte[])entry.Properties["objectGUID"].Value);
The objectSid is a bit more complicated. With a little help from PInvoke.net[^], the following should work:
[DllImport("kernel32.dll", SetLastError=true)]
private static extern IntPtr LocalFree(IntPtr hMem);
[DllImport("advapi32", CharSet=CharSet.Auto, SetLastError=true)]
private static extern bool ConvertSidToStringSid(
[MarshalAs(UnmanagedType.LPArray)] byte[] pSID,
out IntPtr ptrSid);
public static string FormatSid(byte[] sid)
{
if (null == sid || 0 == sid.Length)
throw new ArgumentNullException("sid");
IntPtr ptrSid;
if (!ConvertSidToStringSid(sid, out ptrSid))
throw new System.ComponentModel.Win32Exception();
try
{
return Marshal.PtrToStringAuto(ptrSid);
}
finally
{
LocalFree(ptrSid);
}
}
...
string objectSid = FormatSid((byte[])entry.Properties["objectSid"].Value);
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
string select = "Id = " + id + " AND Address = "+address+ " AND Record ="+record;
datarow[] rowa = db.var.Select(select);
id, address are variable int's and record variable string.
the problem here is that the integers are accepted but the string is not. it throws an exception: "Cannot find collumn[schools]". schools is the value of the string. the collumn name must be Record and string record is a value of a row that belongs to that collumn.
if i make a int of record, then i will accepted. But it doesn't accept a string... why?????????????
|
|
|
|
|
Your SQL WHERE command is translated to this: Lets say Id=2, address=1, record="hello":
Id=2 AND Adress=1 AND Record=hello
This is actually saying that Column [Record] should de equal to Column [hello]. That's why ur getting that error. The correct WHERE command should state that hello is a string:
Id=2 AND Adress=1 AND Record='hello'
Thus ur filter command must be:
string select = "Id = " + id + " AND Address = "+address+ " AND Record ='" + record + "'";
|
|
|
|
|
ooooww thankss. yes it worksss finee noww..
|
|
|
|
|
In my C# code i have a variable EmbedTextBox.Text = this.OpenFileDialog;
I want to use that same variable's contents in my HTML code e.g.
"<html><value=mms://server/EmbedTextBox.Text></html>"
which does not work.
is there an easy of doing this?
|
|
|
|
|
You need to programatically change the content of "value" during the creation of the HTML-Code.
Remember, even if you have a PHP, ASP or whatever script, it still needs to feed the browser valid HTML-code. So, what the server reads:
<?PHP
echo "<html><head>"
echo "<title>" + $ver + "th version of my site</title></head><body></body></html>"
?>
and sends
"<html></head><title>7th version of my site</title></head><body></body></html>"
Basically, in your code, the browser probably understands that it should fill the textbox with "mms://......." as a string, not with the content behind that link. This you would have to do via client- or server-side scripts, preferrably server-side ones.
Cheers
Sid
|
|
|
|
|
Hi all,
I have a question on c# dll loading in .Net.
Let say two dlls, dll A and dll B, object 1 in dll A
refers to an object 2 in dll B. So, if the object1
is running and invoke object 2 in dll B, will the whole dll B being loaded in the memory or just the
object 2 being loaded ? I ask this question coz I concern on the amount of memory usage.
Thanks
|
|
|
|
|
Hai pyhtang,
At runime, while obj in dll A , refers to obj in dll B,,,, only that particluar object will get loaded in to memory.
A dll is nothing but a class library, hence a dll can contain multiple classes. instatntiating a single class will load only that particlar object into memory.
Regs,
Manivannan.P
|
|
|
|
|
|
Why!?!
I found this interesting bit of text in the C# specification at MSDN here[^], when trying to find out why my code isnt working:
First, the set of all accessible members named N declared in T and the base types of T is constructed. Declarations that include an override modifier are excluded from the set.
Can anyone explain to me why? It seems illogical.
Consider the following:
class A {
public virtual int Foo () { return 1; }
}
class B : A {
new int Foo () { return 2; }
static void Main () { System.Console.WriteLine (new C ().Foo ()); }
}
class C : B {
public override int Foo () { return 3; }
It outputs 2, because the code is executed in B. If B didn't define a Foo() method, it would output 1. Logically (well, to me anyway) it should output 3!
--
Dave
|
|
|
|
|
Hi David.
w.r.to, the code sample,,,,
class B : A {
new int Foo () { return 2; }
static void Main () {System.Console.WriteLine (new C ().Foo ()); }
}
This is an apt example for Hiding Methods. The statement 'new int Foo () { return 2; }' in Class B , informs the compiler that the base class member has been hidden and hence it continues executing the method in B.
w.r.to the statement,
If B didn't define a Foo() method, it would output 1....check out it would output only '3'.
I hope is this what you wanted to clarify.
regards,
Manivannan.P
|
|
|
|
|
I'm having problems trying to figure out where to put an Equals override so ArrayList.Contains(object) will work with a class i have made.
this is what i have.
public class CField
{
public string m_FieldName;
...
}
public class CClause
{
public ArrayList alCField = new ArrayList();
...
{
and i want to do this
if(clause.alCField.Contains(string aFieldName)){...}
This ^^ if statment always fails. I've tryed the folowing in CField:
public override bool Equals(Object obj)
{//Check for null and compare run-time types.
if (obj == null || GetType() != obj.GetType()) return false;
CField f = (CField)obj;
return (this.m_FieldName == f.m_FieldName);
}
My way of thinking says that the abouve if should call the override but it dosn't so i'm stuck. I'm starting to miss the old STL.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
An ArrayList doesn't support searching based on a key (in your case, m_FieldName).
You should implement IComparable and use another container, e.g., a SortedList, wich will allow you to search based on a key.
Yes, even I am blogging now!
|
|
|
|
|
I realized the problem was somewhere else in the code
I did want to point out that while ArrayList doesn't support a key search My_al[keyName] it has two search options, Contains which leverages off of Equals, and BinarySearch which leverages off of the IComparable interface.
Is there an article here that explains how to override Equals and IComparable. The help on MSDN doesn’t give a complex example.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
is there a way i can read a file that was create with print to file (the pcl file) and do a print preview on it
thanks
chad
|
|
|
|
|
hello i am new to C# and im trying to create some arrays
im trying to use an enum to specify the size of the arrow but its not allowing me to do so
here is an example
enum Size {MaxSize = 1};
int[] array;
array = new int[Size.MaxSize]
however when i try to do this im getting compile errors
can someone can me some pointers as to how to work with C# arrays
|
|
|
|
|
new int [] {Size.MaxSize }
You may have to cast it to an int as well.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Try this:
enum Size {MaxSize = 1};
int[] array;
array = new int[(int)Size.MaxSize]
|
|
|
|
|
Hi,
I want to be able to Align the Text (in each column) when printing ListView control. I was able to achieve this by creating rectangles. The RightAlign dosn't seem to work perfectly... any ideas why? Is there a better way to Align the text in each column when printing?
for (int row = 0; row < lv.Items.Count; row++)
{
int nextColumnPosition = lv.Bounds.X;
RectangleF drawRect;
StringFormat stringFormat = new StringFormat();
for (int col = 0; col < lv.Items[row].SubItems.Count; col++)
{
if (lv.Columns[col].TextAlign == HorizontalAlignment.Right)
{
drawRect = new RectangleF(nextColumnPosition + leftMargin, (lv.Items[row].Bounds.Y + lv.Bounds.Y) + topMargin, lv.Columns[col].Width - 3, lv.Bounds.Height);
stringFormat.Alignment = StringAlignment.Far;
}
else if (lv.Columns[col].TextAlign == HorizontalAlignment.Center)
{
drawRect = new RectangleF(nextColumnPosition + leftMargin, (lv.Items[row].Bounds.Y + lv.Bounds.Y) + topMargin, lv.Columns[col].Width, lv.Bounds.Height);
stringFormat.Alignment = StringAlignment.Center;
}
else
{
drawRect = new RectangleF(nextColumnPosition + leftMargin + 3, (lv.Items[row].Bounds.Y + lv.Bounds.Y) + topMargin, lv.Columns[col].Width, lv.Bounds.Height);
stringFormat.Alignment = StringAlignment.Near;
}
//print data
g.DrawString(lv.Items[row].SubItems[col].Text, lv.Items[row].Font, Brushes.Black, drawRect, stringFormat);
//Add the width of the current column to get your next column position
nextColumnPosition += lv.Columns[col].Width;
}
}
thanks,
ron
|
|
|
|
|
I have some "large" image data stored in a message queue, and have a remote program to read from the message queue. The first call of reading queue often takes a long time to finish (20 sec). After that the communication becomes fast. BTW, the message queue is not empty when reading begins.
I tried to run the problem local to the msq, the first call of reading did not cause any problem. I also tried to read "small" image data, and that was fast too.
Any idea what is happening and how to avoid it?
Thanx
|
|
|
|