c# - ASP.NET MVC5 copy HTTP Post File from temporary memory to server -


as relatively new asp.net , not have great knowledge of of features , capabilities. advice more experienced users.

i trying find best way automatically upload files 1 or more remote computers file server through server side script (java probably). server running windows server 2012 , hosts asp.net mvc website. unfortunately ftp not option due our infrastructure.

i have been investigating file transfer using http post/put & methods between remote computers , file store server using website gateway. have implemented test project upload file server asp.net webpage webpage when user selects file , clicks submit button. extend when webpage handles http post request copies temporary memory server.

any comments appreciated.

regards,

tim

this model.cs

using system;  using system.collections.generic;  using system.linq;  using system.web;  using system.io;  using amrcadpwebdev.controllers;    namespace amrcadpwebdev.models  {      public class filemodels      {          public httppostedfilebase amrcadpfile { get; set; }      }  }

this filecontroller.cs

using system;  using system.collections.generic;  using system.componentmodel.dataannotations;  using system.io;  using system.linq;  using system.web;  using system.web.mvc;    namespace amrcadpwebdev.controllers  {      /// <summary>      /// file controller      /// </summary>      public class filecontroller : controller      {          public actionresult index()          {              return view();          }            #region action            [httppost]          public virtual actionresult fileupload(httppostedfilebase file)          {              bool isuploaded = false;              string message = "file upload failed";                if (modelstate.isvalid)              {                  if (file != null && file.contentlength != 0 )                  {                      string pathforsaving = "\\\\*****\\filestore\\resultsfiles\\";                      string fname = path.combine(pathforsaving, file.filename);                      try                      {                          file.saveas(path.combine(pathforsaving, file.filename));                          isuploaded = true;                          message = "file uploaded successfully!";                      }                      catch (exception ex)                      {                          message = string.format("file upload failed!!: {0} {1}", ex.message, fname);                      }                  }                    return json(new { isuploaded = isuploaded, message = message }, "text/html");              }                return view();          }            #endregion        }     }

this view/index.cs

@model amrcadpwebdev.models.filemodels    <h2>basic file upload</h2>  @using (html.beginform ("fileupload",                          "file",                          formmethod.post,                          new { enctype = "multipart/form-data" }))  {      <label for="file">upload file:</label>      <input type="file" name="file" id="file" /><br><br>      <input type="submit" value="upload file" />      <br><br>      <label for="file">crio file string:</label>      <input type="submit" value="get file" />        <p>          @html.actionlink("get crio", "getfile")      </p>        @viewbag.message  }  @html.displaynamefor(model => model.amrcadpfile)

this works user initiated file select , submit. how adapt manage http post file data save temporary memory server.

i hope explanation clear question please comment.


Comments