Create a Guid Tool For VS 2008 Tools…
This is a very useful topic
//GetUsers
DirectorySearcher searcher = new DirectorySearcher(de);
searcher.Filter = "(objectClass=user)";
searcher.SearchScope = SearchScope.Subtree;
SearchResultCollection results = searcher.FindAll();
UserCollection users = new UserCollection();
users.Users = new User[results.Count];
int index = 0;
foreach (SearchResult result in results)
{
DirectoryEntry directoryEntry = result.GetDirectoryEntry();
users.Users[index] = new User();
users.Users[index].Email = (directoryEntry.Properties["Mail"].Count >= 1) ? directoryEntry.Properties["Mail"][0].ToString() : "";
string DomainName = "";
string distinguishedName = (directoryEntry.Properties["distinguishedName"].Count >= 1) ? directoryEntry.Properties["distinguishedName"][0].ToString() : "";
string[] TempStr = distinguishedName.Split(',');
foreach (string Str in TempStr)
{
if (Str.Contains("DC="))
{
DomainName = Str.Replace("DC=", "");
break;
}
}
string UserName = (directoryEntry.Properties["sAMAccountName"].Count >= 1) ? directoryEntry.Properties["sAMAccountName"][0].ToString() : "";
users.Users[index].UserName = (DomainName != "") ? DomainName + "\\" + UserName : UserName;
users.Users[index].FirstName = (directoryEntry.Properties["givenName"].Count >= 1) ? directoryEntry.Properties["givenName"][0].ToString() : "";
users.Users[index].LastName = (directoryEntry.Properties["Sn"].Count >= 1) ? directoryEntry.Properties["Sn"][0].ToString() : "";
users.Users[index].DisplayName = (directoryEntry.Properties["displayName"].Count >= 1) ? directoryEntry.Properties["displayName"][0].ToString() : "";
users.Users[index].Description = (directoryEntry.Properties["description"].Count >= 1) ? directoryEntry.Properties["description"][0].ToString() : "";
index++;
}
//Get Trusted Domains
SearchResultCollection resultCollection = searchResultCollection;
ArrayList arrList = new ArrayList();
if (resultCollection != null)
{
foreach (SearchResult sr in resultCollection)
{
DirectoryEntry entry = sr.GetDirectoryEntry();
foreach (DirectoryEntry newEntry in entry.Children)
{
if (newEntry.SchemaClassName == "trustedDomain")
{
arrList.Add(newEntry.Name.Substring(3));
}
}
}
}
If You want to make an application that mange An IIS Virtual paths or application a very Good Reference will be at that link Mange IIS
copy $(TargetPath) $(ProjectDir)gac\
"C:\ToolPath\WSPBuilder.exe" -solutionpath $(ProjectDir) -outputpath $(ProjectDir) -WSPName $(TargetName).wsp -buildwsp
cd $(ProjectDir)
"C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE"-o upgradesolution -filename $(TargetName).wsp -name $(TargetName).wsp -immediate -allowgacdeployment -allowCasPolicies
By adding this few lines to your projects build events..
you will do all these things in one step
you will build your project
will copy the out put to the gac of your project
will build new wsp solution
will update the wsp solution in the administration site.
Happy coding
public class Impersonator : IDisposable
{
#region Public methods.
// ——————————————————————
/// <summary>
/// Constructor. Starts the impersonation with the given credentials.
/// Please note that the account that instantiates the Impersonator class
/// needs to have the ‘Act as part of operating system’ privilege set.
/// </summary>
/// <param name="userName">The name of the user to act as.</param>
/// <param name="domainName">The domain name of the user to act as.</param>
/// <param name="password">The password of the user to act as.</param>
public Impersonator2(
string userName,
string domainName,
string password)
{
ImpersonateValidUser(userName, domainName, password);
}
// ——————————————————————
#endregion
#region IDisposable member.
// ——————————————————————
public void Dispose()
{
}
// ——————————————————————
#endregion
#region P/Invoke.
// ——————————————————————
[DllImport("advapi32.dll", SetLastError = true)]
private static extern int LogonUser(
string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int DuplicateToken(
IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool CloseHandle(
IntPtr handle);
private const int LOGON32_LOGON_INTERACTIVE = 2;
private const int LOGON32_PROVIDER_DEFAULT = 0;
// ——————————————————————
#endregion
#region Private member.
// ——————————————————————
/// <summary>
/// Does the actual impersonation.
/// </summary>
/// <param name="userName">The name of the user to act as.</param>
/// <param name="domainName">The domain name of the user to act as.</param>
/// <param name="password">The password of the user to act as.</param>
private void ImpersonateValidUser(
string userName,
string domain,
string password)
{
WindowsIdentity tempWindowsIdentity = null;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
try
{
if (RevertToSelf())
{
if (LogonUser(
userName,
domain,
password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref token) != 0)
60; {
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
finally
{
if (token != IntPtr.Zero)
{
CloseHandle(token);
}
if (tokenDuplicate != IntPtr.Zero)
{
CloseHandle(tokenDuplicate);
}
}
}
/// <summary>
/// Reverts the impersonation.
/// </summary>
private void UndoImpersonation()
{
if (impersonationContext != null)
{
impersonationContext.Undo();
}
}
private WindowsImpersonationContext impersonationContext = null;
// ——————————————————————
#endregion
}
Create To the XSD design You Want and then use this tool to generate the code behind and classes very useful when trying to serialize objects to be passed in webservices.
Open your Visual Studio Select Tools > External Tools then Click ADD
Title : XSD generation
Command : system Drive:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\xsd.exe
Arguments : /nologo /c /n:CB.Booking.ServiceModel.$(ItemFileName) $(ItemPath)
Initial Directory : $(ItemDir)
Check Use Out Put window Option
Two Functions to Serialize and detribalize any objects to and from xml
private string Serialize(object obj)
{
if (obj == null) { return null; }
XmlSerializer s = new XmlSerializer(obj.GetType());
TextWriter w = new StringWriter();
s.Serialize(w, obj);
w.Close();
return w.ToString();
}
public static object Deserialize(Type type, string xml)
{
if (string.IsNullOrEmpty(xml))
{
return Activator.CreateInstance(type);
}
XmlSerializer s = new XmlSerializer(type);
TextReader tr = new StringReader(xml);
return s.Deserialize(tr);
}
Today i was pleased by getting my Scrum Master Certificate , I can’t wait to actually start using it in real life I think it is a great way of managing and developing software, it just feels right Here is the description and the rules to get certified here and here Basically it is taking [...]