0

私はDevExpressツール、特に必要なすべてのデータを返す「SelectedFiles」プロパティを持つFileManager(レコードの追加、挿入、削除、取得、変更)を使用しています。ただし、選択したファイルを MailMessage.Attachment として使用する方法がわかりません。以下のコードは、電子メールを送信するために機能します。セキュリティのために資格情報とホストの値を変更しました。「SelectedFiles」を介して生成された FileManager コレクションを使用し、それらを電子メールの添付ファイルとして追加する方法について、指示または考えが必要です。可能であればファイルを圧縮したいのですが、この時点では単に添付するだけで問題ありません。何かご意見は?

   Dim fileManager As ASPxFileManager = TryCast(sender, ASPxFileManager)
    If ASPxFileManager1.SelectedFiles IsNot Nothing AndAlso ASPxFileManager1.SelectedFiles.Length > 0 Then
        For i As Integer = 0 To ASPxFileManager1.SelectedFiles.Length - 1
            Dim file = ASPxFileManager1.SelectedFiles.ToString
            Dim attachments As New Attachment(fileManager.SelectedFiles.ToString)???

        Next
    End If
    Try
        Dim mail As New MailMessage("noreply", DropDownEdit.Text)
        Dim smtp_Server As New SmtpClient("host") With {.Credentials = New Net.NetworkCredential("username", "password")}

        mail.Subject = "SUBJECT"
        mail.IsBodyHtml = False
        mail.Body = "Testing"
        smtp_Server.Send(mail)
        successLabel.Text = "Your email was sent successfully."

    Catch ex As Exception

    End Try

End Sub
4

1 に答える 1

0
                Dim attachments As New Attachment(ReadFile(ASPxFileManager1.SelectedFiles(i)), file)
                mail.Attachments.Add(attachments)

以下の関数は、バイトを読み取り、アイテムを MailMessage に添付するために必要でした。

Public Function ReadFile(file__1 As FileManagerFile) As System.IO.Stream
    'This function allows us to pull the bytes from the DB value to render the file.
    Dim filePath As String = (file__1.RelativeName)
    Dim fileData As Byte()
    Using con As New SqlConnection([Global].conn)
        Dim sqlCmd As New SqlCommand()
        sqlCmd.Connection = con
        sqlCmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = file__1.Name
        sqlCmd.Parameters.Add("@APIKey", SqlDbType.Int).Value = Session("_UserAPIKey")
        sqlCmd.CommandText = "SELECT STATEMENT"
        con.Open()
        Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()

        If sqlReader.HasRows Then
            While sqlReader.Read()
                fileData = CType(sqlReader(0), Byte())
            End While
        End If

    End Using

    Return New MemoryStream(fileData)

End Function
于 2013-08-28T16:37:05.490 に答える