H
huan
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);
}
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);
}