Copied to clipboard

Flag this post as spam?

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


  • Kris Janssen 210 posts 569 karma points c-trib
    Oct 14, 2013 @ 08:07
    Kris Janssen
    0

    CWS MVC Umbraco Starter Member registration and File upload

    Hi guys,

    The New MVC based starter by Warren B. is a very nice starting point for learning how to do things in Umbraco.

    In looking at it I was trying to come up with a way to slightly extent the member registration functionality.

    Imagine you'd like to start a "vacancies" page on a website such that users could apply for a job by first registering and next uploading a CV (e.g. as PDF).

    I would imagine you could do so by extending the first the member type to also feature a "file upload" property and next also creating the necessary functionality in the "ProfileViewModel" and related.

    However, it is there that I lose track of things and don't really know how to start out.

    Does anybody have an idea?

  • Kris Janssen 210 posts 569 karma points c-trib
    Oct 14, 2013 @ 08:45
    Kris Janssen
    0

    In relation to the above:

    If I add:

    public File CV { get; set; }
    

    To the ProfileViewModel and subsequently add:

     @Html.EditorFor(model => model.CV, new {@class = "form-control", placeholder = "CV File"})
    

    To ProfileEdit.cshtml... temporarily ignoring the controller modifications that are necessary.

    Then I get this:

    result of my trials

    Which, although expected, is not really desired. I would expect an upload control of course :)

  • Kyle 24 posts 63 karma points
    Nov 11, 2013 @ 09:48
    Kyle
    0

    Hey,

    I'm just trying to figure this out as well, did you get anywhere with it?

    Thanks,

    Kyle

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Nov 11, 2013 @ 09:59
    Andy Butland
    0

    Hi Kyle, Chris

    When doing file upload forms in MVC, I've used this.

    In the view model:

    public HttpPostedFileBase CVFile { get; set; }

    In the view, just use the standard HTML file input:

    <input type="file" name="CVFile" />

    Make sure also to have this on your form (as an extra parameter passed to the Html.BeginForm or Html.BeginUmbracoForm) too:

    new { id = "content-form", enctype = "multipart/form-data" }

    And then in the post action for the controller you can access the file like this.

    if (vm.CVFile != null && vm.CVFile.ContentLength > 0)
    {
        // Do the necessary to save the file and attach it to the member property
    }

    Hope that helps - for the bit in comments above (the associating of the file with the member) looks like this thread will help.

    Andy

  • Kyle 24 posts 63 karma points
    Nov 11, 2013 @ 17:53
    Kyle
    0

    Hi Andy,

    I think I'm nearly there, I have the file uploaded & saved.

    However I'm saving the media ID of file to the members upload field, doesn't have the complete link in the admin area.

    Code to upload & save:

    if (model.CVFile != null)
            {
                var mediaService = Services.MediaService;
                //CreateMedia takes the name of the media you are created, the id of the parent and finally the alias of the MediaType that you want the media to be based on.
                var media = mediaService.CreateMedia(model.CVFile.FileName, 1137, "File");
                mediaService.Save(media);
    
                media.SetValue("umbracoFile", model.CVFile);
                //And then save it similar to the above snippet
                mediaService.Save(media);
    
                updateMember.getProperty("CVFile").Value = media.Id;
            }
    

    The link in the admin next to the upload field is : "/media/1152" How do I get the full path to the file ?

    Kind Regards,

    Kyle

Please Sign in or register to post replies

Write your reply to:

Draft