Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2005, 12:08 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to emerald Send a message via MSN to emerald
Default send email attachment error

Hi! I hope anyone of you can help me up in correcting my error as I've work on this email form for few days but my effort in debugging this form is in vain.
This is the code I get from other sources and have some changes but there is an error in :
strfilename = Path.GetFileName(FileInput.PostedFile.FileName)
the error description => System.NullReferenceException: Object reference not set to an instance of an object.
By the way, I've imported the System.web.mail and System.IO , change my HTMLINPUTFILE control to runat="server", encType="multipart/form-date" for form
Following is my email code :
-------------------------------------------------------------------------------------------------------------
 Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click


        Dim msg As New MailMessage

        msg.To = txtTo.Text
        msg.From = txtFrom.Text
        msg.Subject = txtSubject.Text
        ' msg.To = lstconsult.SelectedItem.Value
        msg.Body = txtMsg.Text
        msg.BodyFormat = MailFormat.Text

        Dim strdir As String
        Dim strfilename As String

        strdir = "D:\\emailtemp\\"
        strfilename = Path.GetFileName(FileInput.PostedFile.FileName)
        FileInput.PostedFile.SaveAs(strdir + strfilename)
        msg.Attachments.Add(New MailAttachment(strdir + strfilename))

        Try

            SmtpMail.Send(msg)

        Catch ex As Exception

            Response.Write(ex)

        Finally

            Response.Write("Your E-mail has been sent sucessfully")
        End Try

        ' Uploaded file deleted after sending e-mail
        File.Delete(strdir + strfilename)

    End Sub
--------------------------------------------------------------------------------------------
I'll appreciate a lot if any of you can help me solve this problem..


Elena





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using vb6 to send email with attachment LeonMK Pro VB 6 3 August 25th, 2011 01:56 AM
Macro to send an email with an attachment in it samputha Excel VBA 2 August 13th, 2009 09:12 PM
how to send email with attachment using JSP kirtesh4u J2EE 0 May 19th, 2007 01:17 AM
error sending email with attachment using CDO archanahs Classic ASP Professional 1 May 25th, 2006 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.