Novell.Directory.Ldap.LdapUrl.ToString C# (CSharp) Method

ToString() public method

Returns a valid string representation of this Ldap URL.
public ToString ( ) : System.String
return System.String
        public override System.String ToString()
        {
            System.Text.StringBuilder url = new System.Text.StringBuilder(256);
            // Scheme
            if (secure)
            {
                url.Append("ldaps://");
            }
            else
            {
                url.Append("ldap://");
            }
            // Host:port/dn
            if (ipV6)
            {
                url.Append("[" + host + "]");
            }
            else
            {
                url.Append(host);
            }

            // Port not specified
            if (port != 0)
            {
                url.Append(":" + port);
            }

            if (((System.Object) dn == null) && (attrs == null) && (scope == DEFAULT_SCOPE) && ((System.Object) filter == null) && (extensions == null))
            {
                return url.ToString();
            }

            url.Append("/");

            if ((System.Object) dn != null)
            {
                url.Append(dn);
            }

            if ((attrs == null) && (scope == DEFAULT_SCOPE) && ((System.Object) filter == null) && (extensions == null))
            {
                return url.ToString();
            }

            // attributes
            url.Append("?");
            if (attrs != null)
            {
                //should we check also for attrs != "*"
                for (int i = 0; i < attrs.Length; i++)
                {
                    url.Append(attrs[i]);
                    if (i < (attrs.Length - 1))
                    {
                        url.Append(",");
                    }
                }
            }

            if ((scope == DEFAULT_SCOPE) && ((System.Object) filter == null) && (extensions == null))
            {
                return url.ToString();
            }

            // scope
            url.Append("?");
            if (scope != DEFAULT_SCOPE)
            {
                if (scope == LdapConnection.SCOPE_ONE)
                {
                    url.Append("one");
                }
                else
                {
                    url.Append("sub");
                }
            }

            if (((System.Object) filter == null) && (extensions == null))
            {
                return url.ToString();
            }

            // filter
            if ((System.Object) filter == null)
            {
                url.Append("?");
            }
            else
            {
                url.Append("?" + Filter);
            }

            if (extensions == null)
            {
                return url.ToString();
            }

            // extensions
            url.Append("?");
            if (extensions != null)
            {
                for (int i = 0; i < extensions.Length; i++)
                {
                    url.Append(extensions[i]);
                    if (i < (extensions.Length - 1))
                    {
                        url.Append(",");
                    }
                }
            }
            return url.ToString();
        }

Usage Example

		private void InitToRootDse(string host,int port)
		{
			if ( host == null )
				host = DefaultHost;
			if ( port < 0 )
				port = DefaultPort;	
		
			LdapUrl rootPath = new LdapUrl (host,port,String.Empty);
			string [] attrs = new string [] {"+","*"};
			DirectoryEntry rootEntry = new DirectoryEntry (rootPath.ToString (),this.Username,this.Password,this.AuthenticationType);
			DirectorySearcher searcher = new DirectorySearcher (rootEntry,null,attrs,SearchScope.Base);

			SearchResult result = searcher.FindOne ();			
			// copy properties from search result
			PropertyCollection pcoll = new PropertyCollection ();
			foreach (string propertyName in result.Properties.PropertyNames) {
				System.Collections.IEnumerator enumerator = result.Properties [propertyName].GetEnumerator ();
				if (enumerator != null)
					while (enumerator.MoveNext ())
						if (String.Compare (propertyName,"ADsPath",true) != 0)
							pcoll [propertyName].Add (enumerator.Current);
			}			
			this.SetProperties (pcoll);
			this._Name = "rootDSE";
		}
All Usage Examples Of Novell.Directory.Ldap.LdapUrl::ToString