I am trying to upload a file to server from html post.
<form action="insertBlogCat.aspx" method="post" enctype="multipart/form-data">
<input id="uploader" name="userfile" type="file" />
<br /><br />
<input type="submit" value="Upload" id="pxUpload" />
<input type="reset" value="Clear" id="pxClear" />
</form>
My server side code:
protected System.Web.UI.HtmlControls.HtmlInputFile CatBlogImgFile;
private void Insert()
{
if ((CatBlogImgFile.PostedFile != null) && (CatBlogImgFile.PostedFile.ContentLength > 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.");
}
}
But CatBlogImgFile.PostedFile value is always null after posting from HTML file. PLease help. Thanks in advance.