Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • simon eriksen 24 posts 113 karma points
    Jun 01, 2018 @ 07:33
    simon eriksen
    0

    No overload for method 'SetValue' takes '3' arguments

    I'm trying to upload a file to the media archive but when i dont hardcode the parentnode in my SetValue i get this error "No overload for method 'SetValue' takes '3' arguments"

    This gives me the error

    System.Web.HttpFileCollectionBase files = Request.Files;
    string[] fieldNames = files.AllKeys;
    
    for (int i = 0; i < fieldNames.Length; ++i)
    {
    string field = fieldNames[i];
    
    
    if(field == "kontraktfile" && Request.Files[i].ContentLength > 0){
    var kontrakt = _mediaService.CreateMedia(Request.Files[i].FileName, Umbraco.Media(1263).Id, "File");
    s = Request.Files[i].InputStream;
    kontrakt.SetValue("umbracoFile", Request.Files[i].FileName, s);
    s.Close();
    _mediaService.Save(kontrakt);
    }
    

    This does not

    System.Web.HttpFileCollectionBase files = Request.Files;
    string[] fieldNames = files.AllKeys;
    
    for (int i = 0; i < fieldNames.Length; ++i)
    {
    string field = fieldNames[i];
    
    
    if(field == "kontraktfile" && Request.Files[i].ContentLength > 0){
    var kontrakt = _mediaService.CreateMedia(Request.Files[i].FileName, 1263, "File");
    s = Request.Files[i].InputStream;
    kontrakt.SetValue("umbracoFile", Request.Files[i].FileName, s);
    s.Close();
    _mediaService.Save(kontrakt);
    }
    

    So i dont really understand why Umbraco.Media(1263).Id and 1263 isnt identical. This is on Umbraco 7.10.4.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 01, 2018 @ 07:35
    Dave Woestenborghs
    0

    WHen you do Umbraco.Media(1263) you will get a dynamic object representing your media item.

    But the method CreateMedia needs only the integer id.

    Dave

  • simon eriksen 24 posts 113 karma points
    Jun 01, 2018 @ 07:46
    simon eriksen
    0

    Hello Dave

    Convert.ToInt32(Umbraco.Media(1263).Id)
    

    Doesnt work either. how can i set the ParentId as an integer without hardcoding it?

  • simon eriksen 24 posts 113 karma points
    Jun 01, 2018 @ 07:48
    simon eriksen
    0
     Umbraco.Media(CurrentPage.mediaMappe.Id).Children().First().Id
    

    is what i want to do for the ParentId.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 01, 2018 @ 08:14
    Dave Woestenborghs
    0

    Hi Simon,

    So if understand correctly "mediaMappe" is media picker property on your doctype ? What did the user select there ? A folder ?

    Dave

  • simon eriksen 24 posts 113 karma points
    Jun 01, 2018 @ 08:37
    simon eriksen
    0

    Hi Dave

    Yes Its a media picker where i've selected a folder. the first child of that folder is also a folder.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 01, 2018 @ 08:44
    Dave Woestenborghs
    100

    Hi Simon,

    I think you need the following code :

    // get the media item assigned in content
    var mediaItem = Model.Content.GetPropertyValue<IPublishedContent>("mediaMappe");
    
    // get first chidl folder
    var firstChildFolder = mediaItem.Childeren().First();
    

    Then you can use firstChildFolder.Id as the id you pass in when you create the media item.

    Dave

  • simon eriksen 24 posts 113 karma points
    Jun 04, 2018 @ 10:58
    simon eriksen
    0

    That worked. Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft