如何在VB.NET中移动文件? [英] How do I move a file in VB.NET ?
问题描述
大家好,
我正在使用vb.net 2013.我有一个程序向我的客户发送电子邮件。这封电子邮件有2个附件。一个word文档和一个PDF文件。我的程序在vb.net中使用OpenFileDialog收集这两个文件路径。收集这些路径后,我将它们存储在字符串列表中。然后我使用MailMessage类发送这些文件。发送电子邮件后,我需要将这些文件移动到特定的文件夹中。但我收到一条错误消息,显示一个进程正在使用这些文件。我如何移动这些文件?
现在,我正在使用一种解决方法。我只是在发送邮件后将文件路径保存在文本文件中。之后,在表单加载事件中,我的程序将读取这些路径并移动所有文件。
这是我发送电子邮件的功能。
我的尝试:
Hi all,
I am using vb.net 2013. I have a program to send an email to my clients. This email has 2 attachments. One word document and one PDF file. My program collecting both these file paths with a "OpenFileDialog" in vb.net. After collecting these paths, i store them in a list of string. Then i send these files using MailMessage class. After sending emails, i need to move these file into a specific folder. But i got an error message which shows one process is using these files. How do i move these files ?
Now, i am using a work around. I just save the file paths in a text file after sending mails. And later, in form load event, my program will read these paths and move all the files.
Here is my function to send an email.
What I have tried:
Public Function SendMail()
Dim Result As Boolean = False
Try
Dim mail As New MailMessage
mail.Subject = Me.m_Subject
mail.To.Add(Me.m_MailAddress)
If Me.m_ccStatus = True Then
mail.CC.Add(Me.m_CC)
End If
mail.From = New MailAddress(Me.m_Credents.UserName)
mail.Body = Me.m_BodyText
Dim attachF As Net.Mail.Attachment
For Each i As String In Me.m_ListOfAttachments
attachF = New Net.Mail.Attachment(i)
mail.Attachments.Add(attachF)
Next
Dim smtp As New SmtpClient(Me.m_SmtpClient)
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential(Me.m_Credents.UserName, Me.m_Credents.PassWord)
smtp.Port = Me.m_PortNumber
smtp.Send(mail)
Result = True
Catch ex As Exception
Throw New Exception("Can't send e-mail")
End Try
推荐答案
仅回答从未答复的队列中删除 - 由OP解决。
Answered only to remove from unanswered queue - solved by OP.
这篇关于如何在VB.NET中移动文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!