How to get a file by it's guid?

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

Hi there,

I have stored an image on my page to use as a PageHeaderImage. Now the GUID is stored within the databse but I cannot get this value into my template file (ascx).

How can I get this GUID within the template file and how can I convert it to an image URL?

Thanks in advance!

Correct Answer

Jan Hermann answered on September 12, 2016 13:02

Please switch your layout type to HTML and enter this macro to your layout:

{%CurrentDocument.GetValue("PageHeaderImage")|(identity)GlobalAdministrator%}.aspx

0 votesVote for this answer Unmark Correct answer

Recent Answers


Kristian Bortnik answered on September 12, 2016 13:04

If you have the GUID of the file, you could do the following:

var attachmentUrl = AttachmentInfoProvider.GetAttachmentUrl(fileGuid, nodeAlias);

fileGuid would be the GUID of the file, and nodeAlias would be the alias of the page that the file is uploaded to (this is usually a URL-friendly version of the DocumentName). You will get a URL similar to: /getattachment/1c569cc8-c6aa-4b61-862c-62fad15f39f9/MyPage.aspx

0 votesVote for this answer Mark as a Correct answer

Lennard van Diggelen answered on September 12, 2016 16:27

Thank you! Both methods worked!

0 votesVote for this answer Mark as a Correct answer

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