We have few downloaded HTML pages, with broken links (relative paths), and we have the original URL each page was downloaded from.

We are converting all relative links to Absolute links using -

Foreach (anchorElement in page) -
    Uri.TryCreate( originalPageURI, hrefRelativeURI, hrefAbsoluteURI )

This works for most of the cases except for the following case -

originalPageURI = http://somewebsite.com/post.jsp?item=22

hrefRelativeURI = ?item=97

What would be the input parameter for Uri.TryCreate() for above case where TryCreate() fails ?

有帮助吗?

解决方案

You can't solve your problem with Uri because ?item=97 is not a relative path but instead a query string.

So, what you have to do is construct your new URL joining the parts by hand.

You should use:

  • originalFolderPath, as the portion of your original URL up to the last '/'. You can join the "true" relative paths to this one to get the absolute uri. (i.e. those not starting with ?)

  • originalFilePath, as the portion of your original URL up to the '?'. You can join the "false" relative paths to this portion. The false are those representing the query string parameters (i.e. those starting with ?).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top