.Net Web Service Studio broke since .NET 2.0

Since I installed .NET 2.0, when I try to use the Web Service studio it would complain about partial classes when pointed at certain webservices.

To remedy this tell studio which runtime is supported

Create a WebServiceStudio.exe.config file with this in it

<configuration>
    <startup>
      
<supportedRuntime version=”v1.1.4322″ />
    </startup>
</
configuration>

That should work now.

Find a user in AD and display LastLogon (plus others) in c#

I have been trying to print the lastLogin time from active directory, its taken about an hour of coding testing and googling,  but I have done it.

First you have to get your AD entry.  Now I work in a place with a few domains so I narrowed my search down a bit by domain, but I bet you can figure out how to tweak it.

Then there is some funky code to convert the AD largeint into a date time and there you are all done

(This is an example so as for naming and exception handling i recommend you do it right)

string login=”funky\\simon”;
string[] keys= {”displayName”,”LastLogon”,”mail”};
string domain,name;

domain=login.Split(’\\’)[0];
name=login.Split(’\\’)[1];

System.DirectoryServices.DirectoryEntry o=
      
new System.DirectoryServices.DirectoryEntry(”LDAP://dc=” + s + “,dc=binaryjam,dc=com”);

System.DirectoryServices.DirectoryEntry p=null;

System.DirectoryServices.DirectorySearcher search=
                     
new System.DirectoryServices.DirectorySearcher(o);

search.Filter = String.Format(”(SAMAccountName={0})”, name);

foreach (string key in keys)
{
   search.PropertiesToLoad.Add(key);
}

p=search.FindOne().GetDirectoryEntry();

foreach (string key in keys) {

string adDets=key + ” - “;

try {
  
if(key==”LastLogon”) {
      ActiveDs.IADsLargeInteger li=((ActiveDs.IADsLargeInteger)(p.Properties[key].Value));
      
long date = (long)li.HighPart << 32 | (uint ) li.LowPart;
      DateTime time = DateTime.FromFileTime( date );
      adDets+=time.ToString();
   }
   
else {
      
adDets+=p.Properties[key].Value.ToString();
   }

   //Here I add asDets to a listBox but you do what you like with it
}
catch {//Yes I am a bad man, you do it right}

}

 

I have the followng articles to thank

http://www.codeproject.com/dotnet/QueryADwithDotNet.asp?print=true
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=321717&SiteID=1

 

Reading and Writing Excel Spreadsheets Using ADO.NET C# DbProviderFactory

Nice article on reading and writing spreadsheets.

http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx

Just in time Im going to need this soon.