file upload with mvchttp://forums.asp.net/t/1789391.aspx/1?file+upload+with+mvcWed, 11 Apr 2012 14:58:02 -040017893914917099http://forums.asp.net/p/1789391/4917099.aspx/1?file+upload+with+mvcfile upload with mvc <p>Is there any other way to do file uploads with c# other place the code in controller.</p> <p>I have c# code that create directories attach a random number at the end if directory all ready exist. I need to capture the new created directory file name and up files to that directory on submit.</p> 2012-04-05T04:55:22-04:004917182http://forums.asp.net/p/1789391/4917182.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>I have not understood well your requirements...but<a href="http://www.uploadify.com/"> uplodify</a>&nbsp;is a good plugin, with several options</p> 2012-04-05T05:42:38-04:004917191http://forums.asp.net/p/1789391/4917191.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>Is that C# code running on the client computer and you want to upload the files to a server using a WebApplication? Why not upload the files via de C# application directly?</p> 2012-04-05T05:50:50-04:004917911http://forums.asp.net/p/1789391/4917911.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>&nbsp;I have tried I don't understand how to reference name in &lt;input type&quot;file&quot; name=&quot;fileupload&quot; /&gt; all example :</p> <p>@(htmlBegin(&quot;UpLoad&quot;, &quot;Home&quot;,</p> <pre lang="aspnet" id="pre0">FormMethod.Post,</pre> <p>&nbsp;new {&nbsp;<span class="attr">enctype</span><span class="kwrd">=&quot;multipart/form-data&quot; } ))</span></p> <p><span class="kwrd">Have a full form with other data that has to be recorded.</span></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p>'</p> 2012-04-05T11:39:14-04:004924421http://forums.asp.net/p/1789391/4924421.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>Hi</p> <p>Did you mean that you want to know how to upload file in MVC?</p> <p>If yes, you can&nbsp;use HttpPostedFileBase,&nbsp;like this:</p> <pre class="prettyprint">[HttpPost] public ActionResult Index(HttpPostedFileBase file) { if (file.ContentLength &gt; 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath(&quot;~/App_Data/uploads&quot;), fileName); file.SaveAs(path); } return RedirectToAction(&quot;Index&quot;); }</pre> <p>In the view, you just need:</p> <pre class="prettyprint">&lt;form action="" method="post" enctype="multipart/form-data"&gt; &lt;label for="file"&gt;Filename:&lt;/label&gt; &lt;input type="file" name="file" id="file" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt;</pre> <p>You can get more details from here:<a href="http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx">http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx</a></p> <p>Hope this helpful<br> Regards<br> Young Yang</p> 2012-04-10T08:55:28-04:004925180http://forums.asp.net/p/1789391/4925180.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>I have stored the Path location in a sql server database. Is there a way to search the database and use the Path location column to display all files in that folder.</p> 2012-04-10T14:34:12-04:004925204http://forums.asp.net/p/1789391/4925204.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>folder on the client or on the server?</p> 2012-04-10T14:44:39-04:004925205http://forums.asp.net/p/1789391/4925205.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>You can definitely perform the update in a class outside the controller. You just have to pass it the HttpContext object. That is where the uploaded file is stored by ASP.NET. What you can also do is have your class create the directory structure and return the path back, then just have the controller save the file in the specified path.</p> 2012-04-10T14:45:35-04:004927291http://forums.asp.net/p/1789391/4927291.aspx/1?Re+file+upload+with+mvcRe: file upload with mvc <p>Thanks everyone I figure out. By declaring the&nbsp;HttpPostedFileBase files in each method.</p> <p>allows me to capture the files.&nbsp;</p> <p></p> <p>However if I used this&nbsp;</p> <p>HttpFileCollection files = Request.Files;<br> <br> for(int i =0; i &lt; files.Count; i&#43;&#43;)<br> {<br> HttpPostedFile file = files[i];<br> if(file.ContentLength &gt; 0)<br> {<br> file.SaveAs(folder &#43; file.FileName);<br> }<br> }</p> <p>HttpFileCollection allow for me to upload multiple files for some reason I can't use with mvc</p> 2012-04-11T14:58:02-04:00