Changing Auto Publish Media on Upload Programmatically in Episerver

NTS: Ever needed to know if the AutoPublishMedia is set? Here is how and why you should.

Published 11th June 2019
Episerver 11

Last day I was looking for an API for checking “Automatically publish media on upload”. In the UI it is located in Admin/Configuration/System Settings/Editing …


However I couldn’t find it, not even when i googled it…

Where is it??

Well it is saved in tblSiteConfig:

I had to do some reflection in dotPeek searching for “AutoPublishMediaOnUpload” to find the API in EPiServer.Cms.Shell.SiteConfigurationRepositoryExtensions

API for AutoPublishMediaOnUpload

By using EPiServer.Cms.Shell.SiteConfigurationRepositoryExtensions you get some extention methods to ISiteConfigurationRepository

Example use:

Why do I need to check AutoPublishMediaOnUpload?

When you’re doing some saving programmatically on media and you don’t know how the editors wants it, normally (probably) it is published on upload, but what if the admins changes this behavior? this is how you future proof it:

EXTRA: Saving a custom property on site level

Example

Beware! SiteConfigurationRepository is unsupported INTERNAL API! Not covered by semantic versioning; might change without notice.

Results in

Data being saved in tblSiteConfig

Retrieve value

Further reading:

About the author

Luc Gosso
– Independent Senior Web Developer
working with Azure and Episerver

Twitter: @LucGosso
LinkedIn: linkedin.com/in/luc-gosso/
Github: github.com/lucgosso

Like it? please up vote
0