How to upload file to server from HTML Post ASP.NET
<p>I am trying to upload a file to server from html post.</p>

<pre><code>&lt;form action="insertBlogCat.aspx" method="post" enctype="multipart/form-data"&gt;

        &lt;input id="uploader" name="userfile" type="file" /&gt;

        &lt;br /&gt;&lt;br /&gt;

        &lt;input type="submit" value="Upload" id="pxUpload" /&gt;
        &lt;input type="reset" value="Clear" id="pxClear" /&gt;
    &lt;/form&gt;
</code></pre>

<p>My server side code:</p>

<pre><code>protected System.Web.UI.HtmlControls.HtmlInputFile CatBlogImgFile;
 private void Insert()
        {

            if ((CatBlogImgFile.PostedFile != null) &amp;&amp; (CatBlogImgFile.PostedFile.ContentLength &gt; 0))
            {
                string fn = System.IO.Path.GetFileName(CatBlogImgFile.PostedFile.FileName);
                string SaveLocation = Server.MapPath("Data") + "\\" + fn;
                try
                {
                    CatBlogImgFile.PostedFile.SaveAs(SaveLocation);
                    Response.Write("The file has been uploaded.");
                }
                catch (Exception ex)
                {


                }
            }
            else
            {
                Response.Write("Please select a file to upload.");
            }
        }
</code></pre>

<p>But CatBlogImgFile.PostedFile value is always null after posting from HTML file. PLease help. Thanks in advance.</p>
