UriBuilder.Fragment Property


Gets or sets the fragment portion of the URI.

 property System::String ^ Fragment { System::String ^ get(); void set(System::String ^ value); };
public string Fragment { get; set; }
member this.Fragment : string with get, set
Public Property Fragment As String

Property Value


The fragment portion of the URI.


The following example creates the URI "http://www.contoso.com/index.htm#main".

UriBuilder^ uBuild = gcnew UriBuilder( "http://www.contoso.com/" );
uBuild->Path = "index.htm";
uBuild->Fragment = "main";
Uri^ myUri = uBuild->Uri;
UriBuilder uBuild = new UriBuilder("http://www.contoso.com/");
uBuild.Path = "index.htm";
uBuild.Fragment = "main";

Uri myUri = uBuild.Uri;
Dim uBuild As New UriBuilder("http://www.contoso.com/")
uBuild.Path = "index.htm"
uBuild.Fragment = "main"
Dim myUri As Uri = uBuild.Uri


The Fragment property contains any text following a fragment marker (#) in the URI, including the marker itself. When setting the Fragment property:

  • In .NET Framework, the fragment marker is always prepended to the string, even if one is already present.
  • In .NET 5 (and .NET Core) and later versions, the fragment marker is prepended to the string if it's not already present.


To append a value to an existing fragment in .NET Framework, you must remove the leading fragment marker before setting the property with the new value. This is because .NET Framework always prepends the fragment marker when setting the property. .NET 5 (and .NET Core) and later versions are tolerant to a leading fragment marker, and will only prepend one if necessary.

Applies to