Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
VB.NET
Windows Forms
Fetch items from Datagridview to Attachment
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="luckydead, post: 186025, member: 74969"] Hello can someone help me, How i can fetch the items from datagridview to attach them to email How it will be in function SendMail() Can someone tell me is it correct now , how to read files from Datagridview in attachment [code] Public Sub SendMail() Dim oEmail As MailItem = CType(New Application().CreateItem(OlItemType.olMailItem), MailItem) oEmail.Recipients.Add("emailTo") 'Send TO oEmail.CC = "CopyEmail" 'Send CC oEmail.Recipients.ResolveAll() oEmail.Subject = "Spam - Meow!" oEmail.BodyFormat = OlBodyFormat.olFormatHTML oEmail.Body = "Blah, blah, blah..." oEmail.Importance = OlImportance.olImportanceNormal 'Request read email confirmation oEmail.ReadReceiptRequested = True If DataGridView1.Rows.Count > 0 Then For Each row As DataGridViewRow In DataGridView1.Rows If row.Cells("Name").Tag IsNot Nothing Then Dim MsgAttach As New Attachment(CStr(row.Cells("Name").Tag)) oEmail.Attachments.Add(MsgAttach) End If Next End If oEmail.Recipients.ResolveAll() oEmail.Save() oEmail.Display(False) 'Show the email message and allow for editing before sending oEmail.Send() 'You can automatically send the email without displaying it. End Sub [/code] Button Browse: [code] OpenFileDialog1.FileName = "Folder1" OpenFileDialog1.DefaultExt = "*.*" OpenFileDialog1.FilterIndex = 6 OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) OpenFileDialog1.Multiselect = True Dim saveDirectory As String = ".\Files\" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then If Not Directory.Exists(saveDirectory) Then Directory.CreateDirectory(saveDirectory) End If For Each item As String In OpenFileDialog1.FileNames Dim fileName As String = Path.GetFileName(OpenFileDialog1.FileName) Dim fileSavePath As String = Path.Combine(saveDirectory, fileName) File.Copy(OpenFileDialog1.FileName, fileSavePath, True) Next End If BindDataGrid() [/code] [code] Private Sub BindDataGrid() Dim filePaths As String() = Directory.GetFiles(".\Files\") Dim dt As DataTable = New DataTable() dt.Columns.Add("Text") dt.Columns.Add("Value") For Each filePath As String In filePaths dt.Rows.Add(IO.Path.GetFileName(filePath), filePath) Next dataGridView1.AllowUserToAddRows = False dataGridView1.Columns.Clear() Dim name As DataGridViewColumn = New DataGridViewTextBoxColumn With { .Name = "Name", .HeaderText = "File Name", .DataPropertyName = "Text", .Width = 100 } DataGridView1.Columns.Insert(0, name) Dim path As DataGridViewColumn = New DataGridViewTextBoxColumn With { .Name = "Path", .HeaderText = "File Path", .DataPropertyName = "Value", .Width = 100 } DataGridView1.Columns.Insert(1, path) DataGridView1.DataSource = dt Dim buttonColumn As DataGridViewButtonColumn = New DataGridViewButtonColumn With { .HeaderText = "", .Width = 60, .Name = "buttonColumn", .Text = "Delete", .UseColumnTextForButtonValue = True } DataGridView1.Columns.Insert(2, buttonColumn) End Sub [/code] [code] Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick If e.ColumnIndex = 2 Then Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex) If MessageBox.Show(String.Format("Do you want to delete Name:{0}?", row.Cells("Name").Value), "Confirmation", MessageBoxButtons.YesNo) = DialogResult.Yes Then File.Delete(row.Cells("Path").Value.ToString()) BindDataGrid() End If End If End Sub [/code] Is it correct to attach the files from the datagridview to the email ? [/QUOTE]
Insert quotes…
Verification
Post reply
VB.NET
Windows Forms
Fetch items from Datagridview to Attachment
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom