EPi Server: Dynamically populate fields defined in the FileSummary.config

288 views Asked by At

So I found out recently that you can change the fields that defines the metadata for each file uploaded in EPi Server's File Management system, simply by editing the FileSummary.config file.

In this FileSummary.config file I can define fields statically with XForms definitions, but is it possible to dynamically populate fields with for example data from pages or defined site categories?

Edit) I see it's possible to define JavaScript in there so that might be an alternative.

1

There are 1 answers

1
Stephen Myers On

One approach would be to use a control adapter to add some controls to the file summary edit /add control

You would register your adapter in the AdapterMappings.browser file as follows:

<browsers>
  <browser refID="Default">
    <controlAdapters>
      ...
      <adapter controlType="EPiServer.UI.Hosting.EditCustomFileSummary"
               adapterType="MyLibrary.Adapters.FileSummaryAdapter, MyLibrary" />
    </controlAdapters>
  </browser>
</browsers>

You would then need to create a control class that derives from ControlAdapter

public class FileSummaryAdapter : ControlAdapter 
{
}

Within here you can create and add you own controls to the 'wrapped' EditCustomFileSummary, here's an example I have used previously to add a Tags control to the file summary dialog:

// Override the OnInit method to ensure our controls are added to the edit control
protected override void OnInit(EventArgs e)
{
    // Some code omitted for clarity
    ...

    // Reference our edit controls
    EditControl = Control as EditCustomFileSummary;
    UnifiedFile selectedFile = EditControl.SelectedFile;
    SaveButton = EditControl.FindControl("SaveButton") as ToolButton;

    // Hook into the save event so we can save the input from our custom controls
    SaveButton.Click += OnSaveButtonClick;

    ...
    _tagsControl.Text = selectedFile.Summary.Dictionary["Tags"].ToString();

    ...
    EditControl.Controls.Add(_tagsControl);
}

Then you would be able to hook into the save event triggered by the 'Save' control in the summary dialog in order to save your custom field as a dictionary item on the files summary property

public void OnSaveButtonClick(object sender, EventArgs e)
{
    // Get a reference to the current file and the summary data
    UnifiedFile selectedFile = EditControl.SelectedFile;

    // Get the tags added
    selectedFile.Summary.Dictionary["Tags"]  = _tagsControl.Text;
}

How and what controls you add can of course be derived by whatever method works for your scenario.