Creating media
One of the most important components when creating media programmatically in your Umbraco project is the Media Service.
It is one of the many services that Umbraco CMS ships with, and it will allow you to interact with the Media API directly from your surface controller.
Learn more about the Media service and Umbraco Services in the general by following the links below in the "Resources" section.
The 3 steps of adding images programmatically to a Umbraco website
When adding images programmatically to your Umbraco website, you will need to go through the following three steps:
Media Types
When talking about media in a Umbraco project it could be one of three different things:
In this video, you will be working with two of those types as you will be creating a folder and an image.
To create either of these three types, you will be using the CreateMedia() method. This method takes three parameters:
SetValue() method
In the previous video, you used the SetValue() method from the Content Service to populate properties on your new content node.
The Media Service has a similar method - it's using the same name, but takes four parameters instead of three:
Resources
Check out the resources below to learn more about MVC and MVC in Umbraco.
Use the bottom below to download an updated version of the ArticleFormController.cs file including comments.
Project login details
User: tv@umbraco.com
Password: 1234567890
In the Surface Controllers chapter, you will learn more about some of the key functionality in Umbraco and how you can use MVC to programmatically add content and media to your Umbraco website.