Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing the uploaded file path to controller action using uploadify
    text
    copied!<p>I'm using <code>uploadify</code> in my MVC3 project. It works fine to upload multiple files and saving to folders as well.</p> <p>How to pass the path of the uploaded file to controller action ? -- I need to pass it to the <code>ExtractingZip</code> action of my controller.</p> <p>To extract the contents of the <code>.zip</code> file, I'm using <a href="http://dotnetzip.codeplex.com/" rel="nofollow">DotNetZip Library</a>.</p> <p>Here is what i've tried so far.</p> <pre><code>$('#file_upload').uploadify({ 'checkExisting': 'Content/uploadify/check-exists.php', 'swf': '/Content/uploadify/uploadify.swf', 'uploader': '/Home/Index', 'auto': false, 'buttonText': 'Browse', 'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif;*.zip', 'removeCompleted': false, 'onSelect': function (file) { if (file.type == ".zip") { debugger; $.ajax({ type: 'POST', dataType: 'json', url: '@Url.Action("ExtractingZip", "Home")', data: ({ fileName: file.name}), // I dont see a file.path to pass it to controller success: function (result) { alert('Success'); }, error: function (result) { alert('error'); } }); } } }); </code></pre> <p>Here is my controller action:</p> <pre><code> [HttpPost] public ActionResult ExtractingZip(string fileName,string filePath, HttpPostedFileBase fileData) { string zipToUnpack = @"C:\Users\Public\Pictures\Sample Pictures\images.zip";// I'm unable to get the filePath so i'm using the path. string unpackDirectory = System.IO.Path.GetTempPath(); using (ZipFile zip1 = ZipFile.Read(zipToUnpack)) { // here, we extract every entry, but we could extract conditionally // based on entry name, size, date, checkbox status, etc. var collections = zip1.SelectEntries("name=*.jpg;*.jpeg;*.png;*.gif;"); foreach (var item in collections) { item.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently); } } return Json(true); } [HttpPost] public ActionResult Index(IEnumerable&lt;HttpPostedFileBase&gt; fileData) { foreach (var file in fileData) { if (file.ContentLength &gt; 0) { string currpath; currpath = Path.Combine(Server.MapPath("~/Images/User3"), file.FileName); //save to a physical location file.SaveAs(currpath); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload