How can I get full file path by guid?

Mr Who asked on June 7, 2021 16:33

Hello,

I can get PermanentUrl and DirectUrl (in this case) but I don't know how can I get full file path by guid or some other way. May be do you know any other options for it? This is code there is I get necessary path link to image

Thank you

Recent Answers


Dmitry Bastron answered on June 7, 2021 17:38

Hi,

You should use GetDirectUrl method explained here. Basically, by guide you can retrieve media library info object, and pass it to a helper to retrieve the URL.

0 votesVote for this answer Mark as a Correct answer

Mr Who answered on June 8, 2021 13:13 (last edited on June 8, 2021 13:28)

Hello Dmitry,

I've create the follow code but I still get the same short link. Maybe kentico cms doesn't allow using full reference? Maybe it can be configured somewhere in Kentico?

MediaFileInfoProvider.GetPreviewFilePath(
                    MediaFileInfoProvider.GetMediaFileInfo(file.Id, AppConfig.Sitename))

Thank you

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on June 8, 2021 18:58

Ok, so this GetDirectUrl method returns you an actual URL of the image. What will be in this URL is defined by a few settings, explained in this documentation article.

For example, if you change in Settings -> Content -> Media URL format from Permanent to Direct file path you'll notice that the same GetDirectUrl method will start returning you a different result. Is this what you are trying to do?

Or do you need to get a file location folder on CMS server so that you can access the file on file system?

0 votesVote for this answer Mark as a Correct answer

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