System.Uri.GetComponents C# (CSharp) Method

GetComponents() public method

public GetComponents ( UriComponents components, UriFormat format ) : string
components UriComponents
format UriFormat
return string
        public string GetComponents(UriComponents components, UriFormat format)
        {
            if (((components & UriComponents.SerializationInfoString) != 0) && components != UriComponents.SerializationInfoString)
                throw new ArgumentOutOfRangeException(nameof(components), components, SR.net_uri_NotJustSerialization);

            if ((format & ~UriFormat.SafeUnescaped) != 0)
                throw new ArgumentOutOfRangeException(nameof(format));

            if (IsNotAbsoluteUri)
            {
                if (components == UriComponents.SerializationInfoString)
                    return GetRelativeSerializationString(format);
                else
                    throw new InvalidOperationException(SR.net_uri_NotAbsolute);
            }

            if (Syntax.IsSimple)
                return GetComponentsHelper(components, format);

            return Syntax.InternalGetComponents(this, components, format);
        }

Usage Example

        public override Stream GetFileStream(Uri path)
        {
            string modFile = path.GetComponents(UriComponents.Host, UriFormat.UriEscaped);
            string filePath = path.GetComponents(UriComponents.Path, UriFormat.UriEscaped);

            return GetFileStream(directory + modFile + "/", filePath);
        }
All Usage Examples Of System.Uri::GetComponents