This is my partial code of fileupload control page. This is the one I’m using. When uploading the file, the filename, postedfile, everything is empty.I tried ajax file upload too. It is showing the error, “Object reference not set to an instance”. Wat is the problem with my coding?
<table>
<tr>
<td align="center">
<span class="txt">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="fpResumenew" runat="server" Visible="false" Width="226px" />
</ContentTemplate>
</asp:UpdatePanel>
</span>
</td>
</tr>
<tr>
<td align="center">
</td>
</tr>
<tr>
<td style="vertical-align: top" align="center">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="btnUpload" Font-Bold="true"
DisabledText="Processing..." Visible="false"
Text="Upload" BackColor="Maroon" ForeColor="White" runat="server" OnClick="btnUpload_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
protected void btnUpload_Click(object sender, EventArgs e)
{
string strname = fpResumenew.FileName.ToString();
if (fpResumenew.PostedFile.FileName.Trim().Length != 0)
{
byte[] binary = new byte[fpResumenew.PostedFile.ContentLength];
binary = fpResumenew.FileBytes;
string doc = fpResumenew.FileName;
string contenttype = fpResumenew.PostedFile.ContentType;
objservice1.UpdateResume(int.Parse(Session["LoginId"].ToString()), doc, binary, contenttype);
Response.Redirect("delresume.aspx?Action=U");
}
else
{
lblmsg.Text = "File is not Found";
lblmsg.Visible = true;
}
}
Nothing works for me.. Problem is that I’m using three more buttons in the same page. The other buttons initializing the file upload control. So, when clicking the upload button, the file name is empty. So, I used another page for uploading the word document. Now, it is working.. !!