Copied to clipboard

Flag this post as spam?

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


  • nojaf 91 posts 300 karma points
    Nov 28, 2013 @ 16:36
    nojaf
    0

    Programmatically set the value of an Upload Field

    Hi,

    as the title says I'm trying to add an uploaded image in C# to my IContent object.

    So far I have:

                IContent articleContent = cs.CreateContent(H1Title, WebConfigManager.GetArtikelContainerId(), ARTICLE_ALIAS, 0);

     

                // Create the media item

                IMediaService ms = App.Helper.HelperFunctions.GetMediaService();

                int mediaContainerId = WebConfigManager.GetMediaArticlesId();

                IMedia mediaItem = ms.CreateMedia(H1Title, mediaContainerId, "Image");

                ms.Save(mediaItem);

                //Save the file and the directory

                Directory.CreateDirectory(mediaRoot + "\\" + mediaContainerId + "\\" + mediaItem.Id);

                IntroPictureHttpBasedFile.SaveAs(mediaRoot + "\\" + mediaContainerId + "\\" + mediaItem.Id + "\\" + IntroPictureHttpBasedFile.FileName);

                //Update the umbracoFile property

                string url = string.Format("/media/" + mediaContainerId + "/{0}/{1}", mediaItem.Id, IntroPictureHttpBasedFile.FileName);

                mediaItem.SetValue("umbracoFile", url);

                ms.Save(mediaItem);

                IntroPicture = url;

    And now I need to know what exactly to use when I call the SetValue method on the articleContent to add the image to the uploadfield.

    Anyone?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies