The Browse button click event Uses an OpenFileDialog control (i.e. here named as odlgAttachment) to allow the user to find an attachment to send, which is then added to an arraylist of MailAttachment objects.
ArrayList arlAttachments;
private void btnBrowse_Click(object sender, System.EventArgs e) { odlgAttachment.InitialDirectory = @"C:\"; odlgAttachment.Filter = "All Files (*.*)|*.*|HTML Files (*.htm;*.html)|*.htm|Microsoft Mail Documents (*.msg)|*.msg|Word Documents (*.doc)|*.doc|Excel Files(*.xl*)|*.xl*|Excel Worksheets (*.xls)|*.xls|Excel Charts (*.xlc)|*.xlc|PowerPoint Presentations (*.ppt)|*.ppt|Text Files (*.txt)|*.txt"; odlgAttachment.FilterIndex = 1; // The OpenFileDialog control only has an Open button, not an OK button. // However, there is no DialogResult.Open enum so use DialogResult.OK. if (odlgAttachment.ShowDialog() == DialogResult.OK) { if (arlAttachments == null) { arlAttachments = new ArrayList(); // Clear the "(No Attachments)" default text in the ListView lstAttachments.Items.Clear(); } arlAttachments.Add(new MailAttachment(odlgAttachment.FileName)); // You only want to show the file name. The OpenFileDialog.FileName // property contains the full path. So Split the path and reverse it // to grab the first string in the array, which is just the FileName. string[] strFileName= odlgAttachment.FileName.Split(Convert.ToChar(@"\")); Array.Reverse(strFileName); //all files are added to textbox lstAttachments.Items.Add(strFileName[0]); } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|