开发者

why am i getting HttpPostedFile object reference null when i put FileUpload control into update panel

Even though i'm selecting some file through file upload control still control never goes into else section of protected void btnUpldRes_Click(object sender, EventArgs e). Is it because ,i've put the fileupload control into update panel???

 

                                    <br />
                                    <br />
                                    <asp:Button ID="btnUpldRes" runat="server" Font-Bold="True" Font-Names="Arial" 
                                        ForeColor="#0033CC" onclick="btnUpldRes_Click" Text="Upload Resume" 
                                        Width="111px" />
                                </td>
                                <td valign="top">
                                    <asp:FileUpload ID="FileUpload1" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>



                </asp:UpdatePanel>

protected void btnUpldRes_Click(object sender, EventArgs e) {

    if (FileUpload1.PostedFile == null)
    {

        LblErrorupload.Visible = true;
    }
    else
    { 

        string connStringUploadResume = ConfigurationManager.ConnectionStrings["myconnstring"].ConnectionString;
        SqlConnection conUploadResume = new SqlConnection(connStringUploadResume);

        string emailAddLogin = User.Identity.Name.ToString();
        string strSqlUploadResume = "UPDATE  gen_profile SET " +
       "resume=@resume where email=@email";
        SqlCommand cmdUploadResume = new SqlCommand(strSqlUploadResume, conUploadResume);

        cmdUploadResume.Parameters.AddWithValue("@email", emailAddLogin);

        HttpPostedFile resume = FileUpload1.PostedFile;
        int resumeSizeInBytes = resume.ContentLength;
        byte[] bufferToReadResume = new byte[resumeSizeInBytes];
        resume.InputStream.Read(bufferToReadResume, 0, resumeSizeInByt开发者_Python百科es);
        cmdUploadResume.Parameters.AddWithValue("@resume", bufferToReadResume);
        conUploadResume.Open();
        int i=cmdUploadResume.ExecuteNonQuery();
        conUploadResume.Close();
        if (i == 1)
        {
            if (LblErrorupload.Visible == true)
            {
                LblErrorupload.Visible = false;
            }
            LblUploadSuccess.Visible = true;
        }
        else
        {
            LblUploadSuccess.Text = "Resume Upload Attempt was not successful"; 
            LblUploadSuccess.Visible = true; 
        }

   }
  }


Try the newer AsyncFileUpload control.

Why it doesn't work: http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx

New article: http://geekswithblogs.net/ranganh/archive/2009/10/01/fileupload-in-updatepanel-asp.net-like-gmail.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜