Posts Tagged ‘.Net’

Create Guid Tool VS 2008

Create a Guid Tool For VS 2008 Tools…

This is a very useful topic

Here

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Get Active Directory Users

//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++; 

 }

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Active Directory Trusted Domains

//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)); 

                } 

            } 

        } 

     }

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Active Directory

Almost Every thing About Active Directory Mangment

Very Usefull link Active Directory

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Make IIS application

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

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Build Events for WSP

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

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Save Current Context

 

using (new Impersonator2(UserName, Environment.UserDomainName, Password)) 

 

{ 

    GenericPrincipal ContextIdentity = new GenericPrincipal(WindowsIdentity.GetCurrent(), null); 

 

    System.Web.HttpContext.Current.User = ContextIdentity; 

 

    Response.Redirect(Url);

 }

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Impersonator

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
    }

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

XSD To CS Tool

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

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

Object Serialize TO Xml

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); 

}

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
 

 

View Abdel-Rahman Awad's profile on LinkedIn

Archives

 

Rss Feed Tweeter button Facebook button Linkedin button Delicious button Digg button