Silverlight program: Get the path URI in the Silverlight. Web project

Source: Internet
Author: User

Overview

SilverlightProgramTo directly access or load a page or resource in a web project that hosts the Silverlight project, we need to retrieve the web URI to perform the next step.

Basic

Uri is a simple representation of resources that can be used by applications on the Intranet or the Internet.UriClass defines attributes and methods to process Uris, including analysis, comparison, and combination.

UriThe class attribute is read-only. To create an object that can be modified, useUribuilderClass.

Relative uri (for example, "/New/index.htm") must be expanded relative to the base Uri, which is absolute. ProvidedMakerelativeuriTo convert an absolute URI to a relative URI if necessary.

If the URI string is a well-formatted Uri and contains a scheme identifier,UriThe constructor will not escape the URI string.

UriThe attribute returns the canonicalized data representation using escape encoding. Any character with a unicode value greater than 127 will be replaced with an equivalent hexadecimal number. To make the URI have a canonicalized format,UriThe constructor performs the following steps:

    • Convert the URI scheme to lowercase.

    • Convert the host name to lowercase.

    • If the host name is an IPv6 address, the normalized IPv6 address is used. Scopeid and other optional IPv6 data will be removed.

    • Remove the default and empty port numbers.

    • Normalize the hierarchical URI path by compressing sequences such as //, //, and // (including escape representation. Note that in some scenarios, escape representation is not compressed.

    • For a layered Uri, if the host does not end with a forward slash (/), add a forward slash.

    • Any reserved characters in the URI must be escaped according to RFC 3986.

In some constructor schemes, as part of the normalization work, the escape representation is compressed. Its URI compresses escape sequences by file, HTTP, https, net. pipe, and net. TCP. All other solutions do not compress escape sequences. For example, if you encode two vertices ".." as "% 2e % 2e" in percent form, the URI constructor compresses this sequence for some schemes. For exampleCodeThe example demonstrates the URI constructor of the HTTP scheme.

Code

Method 1:

// Gets the uri of the subscribed XAML file of the specified XAML content to be rendered.
VaR strfullurl = Application. Current. Host. Source. absoluteuri;
If (Strfullurl. indexof ( " Clientbin " ) > 0 )
{
VaR uristr = Strfullurl. substring ( 0 , Strfullurl. indexof ( " Clientbin " )) + " Report/default. aspx " ;
VaR URI = New Uri (uristr );
}

Method 2:

VaR URI = New Uri (App. Current. Host. source, " ../Report/default. aspx " );

Method 3:

String URL = System. Windows. browser. htmlpage. Document. documenturi. tostring ();
VaR struri = URL. substring ( 0 , URL. lastindexof ( " / " )) + " /Report/default. aspx " ;
VaR URI = New Uri (struri );

Method 4:

Get the webpage root directory

VaR Xapuri = Application. Current. Host. source;
VaR URI = New Uri (Xapuri, " ../ " );

author: memories of lost youth
Source: http://www.cnblogs.com/lukun/
the copyright of this article is shared by the author and the blog. You are welcome to reprint it, but you must keep this statement without the consent of the author, the Article page clearly shows the original connection. If there is any problem, you can use http://www.cnblogs.com/lukun/ contact me, thank you very much.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.