如何在vb中附加文件并保存文件,以及如何发送该文件邮件 [英] how to attach file in vb and save files and how send that file mail

查看:117
本文介绍了如何在vb中附加文件并保存文件,以及如何发送该文件邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我创建了一种表单,例如姓名年龄地址cotacts注释用户以键入所有该标签,我需要将所有详细信息保存为word格式,并且需要在浏览按钮中附加文件并将该文件保存在其他位置,我想以附件的形式发送上述所有详细信息中的邮件,并且我不希望打开其他窗口来发送邮件,我只想单击一下,该详细信息将发送该特定邮件ID example@gmail.com的邮件,就像该用户dnt想要的那样更改邮件ID.


请帮帮我.....

hi i''m create one form like name age address cotacts comments user to type all that tab i need to save that all details in word format and i need to attach file in browse button and save that file in other location and i want to send mail in all the above details with attachment and i dnt want to open other window to send mail i just want to sigle click and and that detail will send mail that particular mail ID example@gmail.com like that user dnt want to change the mail ID..


pls help me.....

推荐答案

要保存文件,您可以使用System.Io
类的FileStram和StreamWriter类. 例如:
To Save file you can use FileStram and StreamWriter Classes form System.Io
For Example :
'Creating object of FileStream.Full filePath is the path where you want to 'Save the file and FileMode is Open/Create/CreateOrOpen.
Dim fs As FileStream=New FileStrea("FullFilePath","FileMode")
Dim sw as StreamWriter=New StreamWriter(fs)
'Writting Textbox Values into the File
sw.writeline("Textbox1.Text")
sw.writeline("Textbox2.Text")
'Closing FileStream
sw.Close
fs.Close
'Disposing the Objects
sw=Nothing
fs=Nothing



要一键发送邮件,请使用以下代码:
''将以下代码放入命令按钮单击事件中



To send Mail on One Click use Following Code :
'' place the following code in a command button click event

Private Sub cmdSendMail_Click()
    Dim objOutlook As Outlook.Application
    Dim objMailItem As Outlook.MailItem
    Set objOutlook = New Outlook.Application
    Set objMailItem = objOutlook.CreateItem(olMailItem)
    With objMailItem.To = "ToAddress"  'recipient's address
        .Subject = "subject"  'subject box content
        .Body = "email message"  ' message goes here
        .Attachment = "c:\path\file.txt"    ' attach any files here
        .Send
    End With
    Set objMailItem = Nothing
    Set objOutlook = Nothing
End Sub


这篇关于如何在vb中附加文件并保存文件,以及如何发送该文件邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆