javascript - File Renaming on Ajax MVC Upload -


i'm trying custom file name when files uploaded using ajax , mvc. i'm unsure how name parsed through formdata.append method..

here jquery code:

  var formdata = new formdata();                 var companyckattachmentfile = document.getelementbyid("companyckattachmentfile").files[0];                 var companyvatattachmentfile = document.getelementbyid("companyvatattachmentfile").files[0];                 formdata.append("companyckattachmentfile", companyckattachmentfile);                 formdata.append("companyvatattachmentfile", companyvatattachmentfile);                   $.ajax({                     cache: false,                     url: 'registerfiles',                     data: formdata,                     type: 'post',                     contenttype: false,                     processdata: false,                     success: regfilessuccess,                     complete: resetwait,                     error: regfailure                 }); 

and on mvc controller side:

 [validateinput(false)]         [httppost]         public actionresult registerfiles(formcollection form)         {             if (request.files.count > 0)             {                 try                 {                     string message = "";                     //  files request object                       httpfilecollectionbase files = request.files;                     (int = 0; < files.count; i++)                     {                         //string path = appdomain.currentdomain.basedirectory + "uploads/";                           //string filename = path.getfilename(request.files[i].filename);                            httppostedfilebase file = files[i];                         string fname;                          // checking internet explorer                           if (request.browser.browser.toupper() == "ie" || request.browser.browser.toupper() == "internetexplorer")                         {                             string[] testfiles = file.filename.split(new char[] { '\\' });                             fname = testfiles[testfiles.length - 1];                         }                         else                         {                             fname = file.filename;                         }                          message += "filename = " + fname + "   ";                          // complete folder path , store file inside it.                           //fname = path.combine(server.mappath("~/uploads/"), fname);                         //file.saveas(fname);                     }                      return json(new                     {                         success = true,                         message = message,                     });                 }                 catch (exception ex)                 {                     //registration complete.                     return json(new                     {                         success = false,                         message = "an error occured uploading files. " + ex.message,                     });                 }             }             else             {                 //registration complete.                 return json(new                 {                     success = true,                     message = "redirect",                 });             }           } 

when saving files, needs save 'companyckattachmentfile' , 'companyvatattachmentfile' file names.

from mvc side, can filename actual file , not name formdata.append method. how name on mvc side?


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -