How to convert GUID of page to an URL

Lennard van Diggelen asked on September 12, 2016 12:26

Hi There,

I have made a custom webpart with a property that has a form control of a page selector. In my ascx.cs file I get the GUID of the page which works fine, but I need the URL. How do I convert this GUID to an URL so I can place it in my webparts?

hope to hear from you!

Correct Answer

Kristian Bortnik answered on September 12, 2016 12:55

One way of accomplishing this:

var nodeId = TreePathUtils.GetNodeIdByNodeGUID(YourGUID, SiteContext.CurrentSiteName);
var node = TreeHelper.SelectSingleNode(nodeId);

You can then access the properties on the TreeNode object (node), such as NodeAliasPath, RelativeURL and AbsoluteURL.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on September 12, 2016 16:23

An alternative is to use a URL Selector vs. the Document Selector. You can get everything you need with the URL to display in another repeater if needed vs. another call.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on September 30, 2016 05:16

Brenden, the URL select just stores the URL. What happens when that changes? Isn't it best practice to store the NodeGUID which will never change and just resolve that to a URL through a custom function?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.