Copied to clipboard

Flag this post as spam?

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


  • Colin McFadden 3 posts 94 karma points
    Jan 04, 2016 @ 22:23
    Colin McFadden
    0

    Use Custom/Surface Controller to manipulate file upload

    Hi All,

    Happy New Year!

    I am trying to undertake a little project that I am hoping I can get some direction on. I have been working with Umbraco for about 8 months, and I want to start extending and implementing some of my ideas.

    What I want is for someone to upload a CSV file (a program/schedule for our company events ), and have the CSV file exported to JSON and deserialized on the view (html) into a table that we designed.

    I have created the script to make those conversions, but Is there a way to create a a model/controller for a macro to collect the file upload info (really just need the resulting file location), so I can reference it in my script? Being able to use macros would be ideal. I created a custom model/controller and I get errors when creating the macro, because the macro is automatically trying to call the PartialViewMacroPage despite referencing my model.

    Would you all have any alternatives to approaching this type of project? I might just be brain dead for the day, but I need to figure out how to pull that file data from the macro.

    Thanks, Colin

  • Dan Patching 31 posts 158 karma points c-trib
    Jan 04, 2016 @ 22:59
    Dan Patching
    0

    Hi Colin,

    Happy new year!

    You could add a form with a file upload element to your view, and then create a surface controller to upload your CSV file.

    [HttpPost]
    public ActionResult UploadCsv( HttpPostedFileBase csvFile )
    {
        csvFile.SaveAs("[path to file]\\my.csv");
        return CurrentUmbracoPage();
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft