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.file name is not working even I have
System.Web.UI.H tmlControls 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.NullRefe renceException: 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:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
JBA.jp.JBAUser. EmailToMembers. SendBtn_Click(O bject
sender, EventArgs e)
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
+108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEv
entHandler.Rais ePostBackEvent( String eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent
(IPostBackEvent Handler sourceControl, String
eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent
(NameValueColle ction postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1263
----------------------------------------------------------
Version Information: Microsoft .NET Framework
Version:1.0.370 5.288; ASP.NET Version:1.0.370 5.288
And Here is my code:
----------------------------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
using System.Configur ation;
using System.Web.Mail ;
using System.Text;
using System.IO;
private void SendBtn_Click(o bject sender,
System.EventArg s e)
{
string source;
string strSQL;
string fileTitle;
int cnt;
cnt=0;
//Send single mail
if (txtEmailAddr.T ext !=
null && txtEmailAddr.Te xt!="")
{
cnt=cnt+1;
//Send email
oMailer = new
System.Web.Mail .MailMessage();
oMailer.From =
txtSender.Text;
oMailer.Subject =
txtSubject.Text .Trim();
oMailer.Body =
txtBody.Text.Tr im();
//oMailer.BodyFor mat=
System.Web.Mail .MailFormat.Htm l;
oMailer.BodyEnc oding=Encoding. UTF8;
oMailer.To=txtE mailAddr.Text.T rim();
// Is there an
attachment?
m_eAttachment =
null;
if
(txtFile.Posted File.FileName != "")
{
string
sPath=@"c:\";
fileTitle
= txtFile.PostedF ile.FileName;
fileTitle
= fileTitle.Subst ring(fileTitle. LastIndexOf("\\ ") + 1);
m_eAttachment = sPath+fileTitle ;
txtFile.PostedF ile.SaveAs(m_eA ttachment);
}