<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: JamieT</title>
    <description>The latest articles on DEV Community by JamieT (@jamietownsend).</description>
    <link>https://dev.to/jamietownsend</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1324135%2F2822b8d2-bdc3-43be-aa7e-a5eefe1a510a.jpeg</url>
      <title>DEV Community: JamieT</title>
      <link>https://dev.to/jamietownsend</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jamietownsend"/>
    <language>en</language>
    <item>
      <title>Programmatically add a new 'Accepted file extension'</title>
      <dc:creator>JamieT</dc:creator>
      <pubDate>Thu, 27 Jun 2024 12:55:30 +0000</pubDate>
      <link>https://dev.to/jamietownsend/programmatically-add-a-new-accepted-file-extension-58h7</link>
      <guid>https://dev.to/jamietownsend/programmatically-add-a-new-accepted-file-extension-58h7</guid>
      <description>&lt;p&gt;In the first post in the series around creating Umbraco &lt;code&gt;Stuff&lt;/code&gt; programmatically is actually something that reminded me to start sharing my journey, and that is I needed to allow editors to upload '.mov' files and for these to be set as a &lt;strong&gt;Video&lt;/strong&gt; media type.&lt;/p&gt;

&lt;p&gt;OTB Umbraco has three extensions which dictate that the file is a &lt;strong&gt;Video&lt;/strong&gt; and these are the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;mp4&lt;/li&gt;
&lt;li&gt;webm&lt;/li&gt;
&lt;li&gt;ogv&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqu4wf7su48ym0waqndtd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqu4wf7su48ym0waqndtd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how do I programmatically add to this list? Let's start by looking at the configuration of this data type. If you get the ID of this data type by looking on the info section. &lt;/p&gt;

&lt;h2&gt;
  
  
  Gather information
&lt;/h2&gt;

&lt;p&gt;The ID for this data type is -100 so let's look at the database&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

select * from umbracoDataType where nodeId = -100


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can see the configuration value by default as below, which matches the screen in Umbraco.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "fileExtensions": [
    {
      "id": 0,
      "value": "mp4"
    },
    {
      "id": 1,
      "value": "webm"
    },
    {
      "id": 2,
      "value": "ogv"
    }
  ]
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now there is a level of risk with this, as this is an Umbraco property they could in theory release an update which modifies this configuration value so we'll need to keep an eye on any upgrades we do to ensure our changes are persisted, if you know of a safer way to do this, do let me know in the comments. &lt;/p&gt;

&lt;p&gt;Ok, so we know what the data looks like, how do we add our new 'mov' extension. &lt;/p&gt;

&lt;h2&gt;
  
  
  Create the configuration and add our new extension.
&lt;/h2&gt;

&lt;p&gt;After a bit of digging, I found the configuration class &lt;code&gt;FileUploadConfiguration&lt;/code&gt; (&lt;a href="https://apidocs.umbraco.com/v13/csharp/api/Umbraco.Cms.Core.PropertyEditors.FileUploadConfiguration.html" rel="noopener noreferrer"&gt;https://apidocs.umbraco.com/v13/csharp/api/Umbraco.Cms.Core.PropertyEditors.FileUploadConfiguration.html&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;So let's create a new instance and add the extensions we want. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

var videoUploadFieldConfig = new FileUploadConfiguration()
{
    FileExtensions =
    [
        new FileExtensionConfigItem
        {
            Id = 0,
            Value = "mp4"
        },

        new FileExtensionConfigItem
        {
            Id = 1,
            Value = "webm"
        },

        new FileExtensionConfigItem
        {
            Id = 2,
            Value = "ogv"
        },

        new FileExtensionConfigItem
        {
            Id = 3,
            Value = "mov"
        }
    ]
};


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Save our new configuration to the database
&lt;/h2&gt;

&lt;p&gt;As we are editing a Data Type you first need to inject &lt;code&gt;IDataTypeService&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Umbraco handles configurations of data types by accepting &lt;code&gt;object?&lt;/code&gt; because each data type can potentially have a different configuration type. So we can simply save using the &lt;code&gt;videoUploadFieldConfig&lt;/code&gt; as the configuration value, as so.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

var dataType = _dataTypeService.GetDataType(name);
if (dataType == null)
    throw new Exception("Data Type not found");

dataType.Configuration = videoUploadFieldConfig;
_dataTypeService.Save(dataType);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Wala!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1u1q9ekjr2q9r4igo966.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1u1q9ekjr2q9r4igo966.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Existing media
&lt;/h2&gt;

&lt;p&gt;Sadly the above will only assign any newly uploaded '.mov' files as a &lt;strong&gt;Video&lt;/strong&gt; type, any existing files will need to be either uploaded again or manually updated.&lt;/p&gt;

&lt;p&gt;Let me know if you want a post about doing this programmatically :)  &lt;/p&gt;

</description>
      <category>umbraco</category>
    </item>
    <item>
      <title>My journey through programmatically creating Umbraco `stuff`</title>
      <dc:creator>JamieT</dc:creator>
      <pubDate>Thu, 27 Jun 2024 12:07:54 +0000</pubDate>
      <link>https://dev.to/jamietownsend/my-journey-through-programmatically-creating-umbraco-stuff-2d4a</link>
      <guid>https://dev.to/jamietownsend/my-journey-through-programmatically-creating-umbraco-stuff-2d4a</guid>
      <description>&lt;p&gt;I've been meaning to start sharing my journey through programmatically creating every document type, data type and everything in-between programmatically via Umbraco Package Migrations. The reason for this is so that I can create isolated packages, which when installed create and configures everything needed for this package without any dependencies. &lt;/p&gt;

&lt;p&gt;Think of this example, I want to give editors a new '&lt;strong&gt;Carousel&lt;/strong&gt;' component they can add to the Block Grid. I would create a new Umbraco package, say as an RCL (Razor Class Lib) and include Umbraco Package Migrations, which in turn creates all of the data types, document types and then adds the new document type as an allowed Element of an Umbraco Grid. &lt;/p&gt;

&lt;p&gt;Cool right? As this is using Umbraco Package Migrations this also gives us the ability to create new versions of the '&lt;strong&gt;Carousel&lt;/strong&gt;' package and Umbraco handles everything for us.&lt;/p&gt;

&lt;p&gt;I am aiming to share how this journey has gone, how I've tackled certain problems and cool things I find out along the way. With Umbraco 14 and a lot of this stuff being created via JS, this may well need to be rewritten/reworked but for the foreseeable future Umbraco 13 is where it's at and perhaps I'll share how I tackle migrating to Bellissima when the time comes!&lt;/p&gt;

&lt;p&gt;Keep an eye out for my first post in this series coming soon. &lt;/p&gt;

</description>
      <category>umbraco</category>
    </item>
  </channel>
</rss>
