how can i save the uploded file ? RRS feed

  • Question

  • I already received the file from front end therefore I need to save it in project rout so what I shall do

    public ActionResultfile(HttpPostedFileBasefile1){

    var fileex = System.IO.Path.GetExtension(file1.FileName).Substring(1);           

    varfilename = System.IO.Path.GetFileName(file1.FileName).Substring(0);          

    intfilesize = file1.ContentLength;

    //I need to save the file in a specific route e.g. /files/



    • Edited by Abadry Wednesday, April 25, 2018 10:27 PM
    Wednesday, April 25, 2018 10:24 PM

All replies

  • Where did you get an HttpPostedFileBase instance?

    If you actually have a file name in file1.FileName, then all you need to do call System.IO.File.Move.  If you actually have an HttpPostedFile, then there is a SaveAs method.

    I'm concerned by your please "save the file in a specific route e.g., /files/".  "Route" is a web app term that refers to URLs.  You will be saving the file to a location on disk.  It's up to your web application to map routes to disk locations.

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Thursday, April 26, 2018 6:50 PM