Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net MVC File Upload Question
    primarykey
    data
    text
    <p>When I want to try the file upload in ASP.Net MVC,I am receive the following error.</p> <pre><code>Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 21: public ActionResult FileUpload(HttpPostedFileBase uploadFile) Line 22: { Line 23: if (uploadFile.ContentLength &gt; 0) Line 24: { Line 25: string filePath = Path.Combine(HttpContext.Server.MapPath ("../../Tarifler/Videolar/"), Source File: D:\yemekizle\yemekizle\Controllers\FileUploadController.cs Line: 23 </code></pre> <p>Here is my code line.</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt; FileUpload &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h2&gt;FileUpload&lt;/h2&gt; &lt;% using (Html.BeginForm("FileUpload", "FileUpload", FormMethod.Post, new { enctype = "multipart/form-data" })) { %&gt; &lt;input name="uploadFile" type="file" /&gt; &lt;input type="submit" value="Upload File" /&gt; &lt;% } %&gt; &lt;/asp:Content&gt; </code></pre> <p>Controller: </p> <pre><code>[HandleError] public class FileUploadController : Controller { public ActionResult FileUpload() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult FileUpload(HttpPostedFileBase uploadFile) { if (uploadFile.ContentLength &gt; 0) { string filePath = Path.Combine( HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(uploadFile.FileName) ); uploadFile.SaveAs(filePath); } return View(); } } </code></pre> <p>Where I wrong? </p> <p>Thanks,</p> <hr> <pre><code> [AcceptVerbs(HttpVerbs.Post)] public ActionResult Upload(HttpPostedFileBase uploadFile) { if (uploadFile.ContentLength &gt; 0) { string filePath = Path.Combine(HttpContext.Server.MapPath("~/resim"), Path.GetFileName (uploadFile.FileName)); uploadFile.SaveAs(filePath); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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