Hi friends i have a error in my file upload control. i select the file that i want to upload, but when i click the upload button. its give the this error. i dont know why this error come.
Error:
Object reference not set to an instance of an object.
here is my Upload Button Code code
protected void Button2_Click(object sender, EventArgs e)
{
string strFileName;
strFileName = FileField.PostedFile.FileName;
string c = System.IO.Path.GetFileName(strFileName);
try
{
Image2.Visible = true;
FileField.PostedFile.SaveAs("C:\\UploadedUserFiles\\" + c);
Image2.Visible = false;
Label2.Visible = true;
}
catch (Exception exp)
{
Label2.Text = exp.Message.ToString();
Label2.Visible = true;
}
}
Here is My page Code
<table cellpadding="0" cellspacing="0" class="style8">
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: right; padding-right: 10px; height: 30px" width="150px">
*Name:</td>
<td width="275px">
<asp:TextBox ID="TextBox2" runat="server" Width="250px"></asp:TextBox>
</td>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #FF0000; padding-left: 10px; text-align: left" width="150px">
</td>
</tr>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: right; padding-right: 10px; height: 30px" width="150px">
*Email Address:</td>
<td width="275px">
<asp:TextBox ID="TextBox4" runat="server" Width="250px"></asp:TextBox>
</td>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #FF0000; padding-left: 10px; text-align: left" width="150px">
</td>
</tr>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: right; padding-right: 10px; height: 30px" width="150px">
*Contact Number:</td>
<td width="275px">
<asp:TextBox ID="TextBox5" runat="server" Width="250px"></asp:TextBox> </td>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #FF0000; padding-left: 10px; text-align: left" width="150px">
</td>
</tr>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: right; padding-right: 10px; height: 30px" width="150px">
*City:</td>
<td width="275px">
<asp:TextBox ID="TextBox6" runat="server" Width="250px"></asp:TextBox></td>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #FF0000; padding-left: 10px; text-align: left" width="150px">
</td>
</tr>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: right; padding-right: 10px; height: 30px" width="150px">
Your CV:</td>
<td width="275px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileField" runat="server" Width="247px" /><br />
<asp:Button ID="Button2" runat="server" Text="Upload" Height="20px"
onclick="Button2_Click" /><asp:Image ID="Image2" runat="server" Visible="False" />
<asp:Label ID="Label2" runat="server" Font-Names="Arial" Font-Size="10pt"
ForeColor="#535353" Text="File Uploaded Successfully" Visible="False"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #FF0000; padding-left: 10px; text-align: left" width="150px">
</td>
</tr>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: right; padding-right: 10px; height: 30px"
width="150px" valign="top">
Describe Yourself: <td width="275px">
<asp:TextBox ID="TextBox8" runat="server" Width="250px" Height="200px"></asp:TextBox></td>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #FF0000; padding-left: 10px; text-align: left"
width="150px" valign="top">
</td>
</tr>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: right; padding-right: 10px; height: 30px" width="150px">
</td>
<td width="275px">
<asp:Button ID="Button1" runat="server" Text="Apply"
onclick="Button1_Click" />
</td>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; color: #FF0000; padding-left: 10px; text-align: left" width="150px">
</td>
</tr>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; font-weight: bold; color: #535353; text-align: left; height: 30px; padding-left: 10px;"
colspan="3">
<asp:Label ID="Label1" runat="server" ForeColor="#009999"
Text="* Your Resume Send Successfully." Visible="False"></asp:Label>
</td>
</tr>
</table>
Thanks in Advance