Developer forum

Forum » Development » How to upload file with ItemCreator

How to upload file with ItemCreator

Anders Ebdrup
Reply

Hi Dw's,

 

How can we upload a file with the ItemCreator? Right now it seems to be through the FileManager, but that doesn't seem to be a good option in the frontend.

 

Best regards, Anders


Replies

 
Mikkel Ricky
Reply

Currently, you cannot upload a file using the item creator (or when editing an item using the item publisher) in the frontend and using the FileManager is not the way to do it.

We are working on figuring out how to handle file fields in the frontend, and we've been discussing if a file field should be just a file selector (e.g. a dropdown list) or if should also support uploading files. It probably should support uploading files, but we will need some additional settings on the field to control if uploading is allowed or not and if picking a file is allowed or not. Any suggestions and comments on this is very welcome.

Best regards,
Mikkel

 
Anders Ebdrup
Reply

Hi Mikkel,

 

I certainly think that it should support uploading files where the settings for BaseDirectory and Extensions set on the field should be respected. As it then can replace the form modules.

 

Best regards, Anders

 
Mikkel Ricky
Reply

Thanks. We have specified this task and a couple of related tasks, and we'll start implementing next week.

Best regards,
Mikkel

 
Lars Larsen
Reply
Sounds great. I miss the file upload feature too. When will you release the new feature?
 
Mikkel Ricky
Reply

We're currently working on this feature and it will be availablie in Dynamicweb 8.5.

Best regards,
Mikkel

 
Lars Larsen
Reply

Thanks, I will look forward to that smiley

 
Peter Terkildsen
Reply

I just looked at the roadmap, and I couldn't find this new feature inside the roadmap. Will this feature still be a part of the release?

 
Mikkel Ricky
Reply

Yes, file uploads in the Item creator will be supported in Dynamicweb 8.5.

Best regards,
Mikkel

 
Peter Terkildsen
Reply

cool :-)

 
Lars Larsen
Reply

Now that DW 8.5 has been releases I have been looking for this new file upload feature but with no luck! Mikkel could you please show me where to find it? Thanks.

 
Mikkel Ricky
Reply
This post has been marked as an answer

As the release notes hint at you just have to add some markup to your item creator template to allow upload of files.

An example template looks like this:

@GetValue("ItemCreator:Edit.Form.Begin")

@foreach (var group in GetLoop("ItemCreator:Edit.Item.Groups")) {
  <fieldset>
    <legend>@group.GetValue("ItemCreator:Edit.Item.Group.Name")</legend>

    <dl>
    @foreach (var field in group.GetLoop("ItemCreator:Edit.Item.Group.Fields")) {
      <dt>@field.GetValue("ItemCreator:Edit.Item.Field.Name")</dt>
      <dd>
        @field.GetValue("ItemCreator:Edit.Item.Field.Control")
        @if (field.GetString("ItemCreator:Edit.Item.Field.EditorType").Contains("Dynamicweb.Content.Items.Editors.FileEditor")) {
          <input type='file' name='@field.GetValue("ItemCreator:Edit.Item.Field.SystemName")' accept='@field.GetValue("ItemCreator:Edit.Item.Field.Extensions")'/>
        }
      </dd>
    }
    </dl>
  </fieldset>
}

<button type='submit'>Create</button>

@GetValue("ItemCreator:Edit.Form.End")

The important part is 

<input type='file' name='@field.GetValue("ItemCreator:Edit.Item.Field.SystemName")' accept='@field.GetValue("ItemCreator:Edit.Item.Field.Extensions")'/>

Best regards,
Mikkel

Votes for this answer: 1
 
Lars Larsen
Reply

Hi Mikkel

Thanks for the superb example. Would have been nice if it was shown in the release note. I didn't understand the explanation in the release note, I think it could have been explained a lot clearer :-)

 
Hans Ravnsfjall
Reply

Ok, but it will be a field just as richtext, text etc. No serverside coding needed?

 
Mikkel Ricky
Reply

It has to be a File field and you have to add a file input control as shown in the example. That's all.

 
Hans Ravnsfjall
Reply

Ok, maybe I´m gonna need you to ellaborate if we get this client.

 
Claus Kølbæk
Reply

Hey,

Used the above for the ItemCreator without any problem - but how would I go about making the same functionality in the ItemPublisher edit instead?

@GetValue("ItemPublisher:Edit.Form") Gives me all the text fields which changes fine on a "Save Changes" and it also list the image chosen in a dropdown - however nothing changes if you change it "Nothing selected".

If I then instead use the ItemPublisher:Edit:Form.Begin and ItemPublisher:Edit:Form.End it seems I only have a loop for the images in the dropdownlist and not a list of all fields as I would expect?

 

You must be logged in to post in the forum