HttpPostedFile problem

Discussion in 'ASP .Net Web Controls' started by huan, Jan 1, 2004.

  1. huan

    huan Guest

    Hi,

    I am creating a function using C# to send emails with
    attachment file. And I am using File Field control to get
    file for attachment. Sending email works fine on
    development machine, however when I deployed it on the
    production machine, it doesn't work. It gives me an error
    as below when I click send email button. And I tried to
    debug it. Seems like File field control's
    postedfile.filename is not working even I have
    System.Web.UI.HtmlControls reference.

    Did anyone ever have similar situation like this? Where
    is the problem? Please help.

    Thank you very much.

    Huan

    -----------------------------------------------------
    Server Error in '/' Application.
    ----------------------------------------------------------

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the
    execution of the current web request. Please review the
    stack trace for more information about the error and
    where it originated in the code.

    Exception Details: System.NullReferenceException: Object
    reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution
    of the current web request. Information regarding the
    origin and location of the exception can be identified
    using the exception stack trace below.

    Stack Trace:


    [NullReferenceException: Object reference not set to an
    instance of an object.]
    JBA.jp.JBAUser.EmailToMembers.SendBtn_Click(Object
    sender, EventArgs e)
    System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    +108

    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEv
    entHandler.RaisePostBackEvent(String eventArgument) +57
    System.Web.UI.Page.RaisePostBackEvent
    (IPostBackEventHandler sourceControl, String
    eventArgument) +18
    System.Web.UI.Page.RaisePostBackEvent
    (NameValueCollection postData) +33
    System.Web.UI.Page.ProcessRequestMain() +1263




    ----------------------------------------------------------
    Version Information: Microsoft .NET Framework
    Version:1.0.3705.288; ASP.NET Version:1.0.3705.288


    And Here is my code:

    ----------------------------
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web.Mail;
    using System.Text;
    using System.IO;

    private void SendBtn_Click(object sender,
    System.EventArgs e)
    {
    string source;
    string strSQL;
    string fileTitle;
    int cnt;

    cnt=0;
    //Send single mail
    if (txtEmailAddr.Text !=
    null && txtEmailAddr.Text!="")
    {
    cnt=cnt+1;

    //Send email
    oMailer = new
    System.Web.Mail.MailMessage();

    oMailer.From =
    txtSender.Text;
    oMailer.Subject =
    txtSubject.Text.Trim();
    oMailer.Body =
    txtBody.Text.Trim();

    //oMailer.BodyFormat=
    System.Web.Mail.MailFormat.Html;

    oMailer.BodyEncoding=Encoding.UTF8;

    oMailer.To=txtEmailAddr.Text.Trim();

    // Is there an
    attachment?
    m_eAttachment =
    null;
    if
    (txtFile.PostedFile.FileName != "")
    {
    string
    sPath=@"c:\";
    fileTitle
    = txtFile.PostedFile.FileName;
    fileTitle
    = fileTitle.Substring(fileTitle.LastIndexOf("\\") + 1);

    m_eAttachment = sPath+fileTitle;

    txtFile.PostedFile.SaveAs(m_eAttachment);
    }

    ..
     
    huan, Jan 1, 2004
    #1
    1. Advertising

  2. hi huan,
    the complete reference is System.Web.UI.HtmlControls.HtmlInputFile
    I dont see your declaration for txtFile. You need to declare it as System.Web.UI.HtmlControls.HtmlInputFile
    and then use it in your code.
    Should work now.


    "huan" <> wrote in message news:031101c3d00c$90395fd0$...
    > Hi,
    >
    > I am creating a function using C# to send emails with
    > attachment file. And I am using File Field control to get
    > file for attachment. Sending email works fine on
    > development machine, however when I deployed it on the
    > production machine, it doesn't work. It gives me an error
    > as below when I click send email button. And I tried to
    > debug it. Seems like File field control's
    > postedfile.filename is not working even I have
    > System.Web.UI.HtmlControls reference.
    >
    > Did anyone ever have similar situation like this? Where
    > is the problem? Please help.
    >
    > Thank you very much.
    >
    > Huan
    >
    > -----------------------------------------------------
    > Server Error in '/' Application.
    > ----------------------------------------------------------
    >
    > Object reference not set to an instance of an object.
    > Description: An unhandled exception occurred during the
    > execution of the current web request. Please review the
    > stack trace for more information about the error and
    > where it originated in the code.
    >
    > Exception Details: System.NullReferenceException: Object
    > reference not set to an instance of an object.
    >
    > Source Error:
    >
    > An unhandled exception was generated during the execution
    > of the current web request. Information regarding the
    > origin and location of the exception can be identified
    > using the exception stack trace below.
    >
    > Stack Trace:
    >
    >
    > [NullReferenceException: Object reference not set to an
    > instance of an object.]
    > JBA.jp.JBAUser.EmailToMembers.SendBtn_Click(Object
    > sender, EventArgs e)
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    > +108
    >
    > System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEv
    > entHandler.RaisePostBackEvent(String eventArgument) +57
    > System.Web.UI.Page.RaisePostBackEvent
    > (IPostBackEventHandler sourceControl, String
    > eventArgument) +18
    > System.Web.UI.Page.RaisePostBackEvent
    > (NameValueCollection postData) +33
    > System.Web.UI.Page.ProcessRequestMain() +1263
    >
    >
    >
    >
    > ----------------------------------------------------------
    > Version Information: Microsoft .NET Framework
    > Version:1.0.3705.288; ASP.NET Version:1.0.3705.288
    >
    >
    > And Here is my code:
    >
    > ----------------------------
    > using System;
    > using System.Collections;
    > using System.ComponentModel;
    > using System.Data;
    > using System.Drawing;
    > using System.Web;
    > using System.Web.SessionState;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Web.UI.HtmlControls;
    > using System.Data.SqlClient;
    > using System.Configuration;
    > using System.Web.Mail;
    > using System.Text;
    > using System.IO;
    >
    > private void SendBtn_Click(object sender,
    > System.EventArgs e)
    > {
    > string source;
    > string strSQL;
    > string fileTitle;
    > int cnt;
    >
    > cnt=0;
    > //Send single mail
    > if (txtEmailAddr.Text !=
    > null && txtEmailAddr.Text!="")
    > {
    > cnt=cnt+1;
    >
    > //Send email
    > oMailer = new
    > System.Web.Mail.MailMessage();
    >
    > oMailer.From =
    > txtSender.Text;
    > oMailer.Subject =
    > txtSubject.Text.Trim();
    > oMailer.Body =
    > txtBody.Text.Trim();
    >
    > //oMailer.BodyFormat=
    > System.Web.Mail.MailFormat.Html;
    >
    > oMailer.BodyEncoding=Encoding.UTF8;
    >
    > oMailer.To=txtEmailAddr.Text.Trim();
    >
    > // Is there an
    > attachment?
    > m_eAttachment =
    > null;
    > if
    > (txtFile.PostedFile.FileName != "")
    > {
    > string
    > sPath=@"c:\";
    > fileTitle
    > = txtFile.PostedFile.FileName;
    > fileTitle
    > = fileTitle.Substring(fileTitle.LastIndexOf("\\") + 1);
    >
    > m_eAttachment = sPath+fileTitle;
    >
    > txtFile.PostedFile.SaveAs(m_eAttachment);
    > }
    >
    > .
    >
    >
     
    Alessandro Zifiglio, Jan 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff
    Replies:
    1
    Views:
    1,909
    Kevin Spencer
    Oct 27, 2003
  2. Guest

    HttpPostedFile

    Guest, Nov 11, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    3,161
    Kevin Spencer
    Nov 11, 2003
  3. huan

    HttpPostedFile problem

    huan, Dec 31, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    745
    vMike
    Jan 5, 2004
  4. Al Smith

    HttpPostedFile.SaveAs

    Al Smith, Aug 30, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    3,743
    Steven Cheng[MSFT]
    Sep 1, 2004
  5. Bruno Piovan

    Re: HttpPostedFile

    Bruno Piovan, Sep 14, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    381
    Bruno Piovan
    Sep 14, 2004
Loading...

Share This Page