I am trying to have form with a file upload in it.
I have to have this form in a macro script. Everything has to be done through the Umbraco UI, so I don't see how I can write a server side controller. I only need to process the file, not save it to the server, if that makes any difference.
I can't figure out how to make this work. I always get 0 count for files uploaded and no file name. Any other form values I put in get passed through, just not the file information.
file upload in razor script - how to do it?
I am trying to have form with a file upload in it.
I have to have this form in a macro script. Everything has to be done through the Umbraco UI, so I don't see how I can write a server side controller. I only need to process the file, not save it to the server, if that makes any difference.
I can't figure out how to make this work. I always get 0 count for files uploaded and no file name. Any other form values I put in get passed through, just not the file information.
Here is my script:
<form runat="server" id="resourceLoad" method="post"> .csv file to import: <input type="file" name="inputFile"/><br /> ID:<input type="text" name="id" /><br /> <input id="resourceLoad" type="submit" value="GO" class="psButton" tabindex="205"> </form> <br /> <hr /> @try { if ( IsPost ) { var fileName = ""; if ( Request.Files.Count > 0 ) { fileName = Path.GetFileName( Request.Files[0].FileName ); } <div>files uploaded = @Request.Files.Count </div> <div>file name = @fileName</div> <div>id = @Request["id"]</div> } } catch (Exception ex) { <div>@ex.ToString()</div> }Example of output (after selecting a file with the file browser)
ok - found the solution, had to add ' enctype="multipart/form-data"' to the form tag.
That is the difference between Friday afternoon brain dead and fresh Monday morning! :)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.