Assuming filename
is a file name only and does not contain other path components:
foreach (string file in Directory.GetFiles(@"M:\", filename + ".*"))
{
yourMailMessage.Attachments.Add(new System.Net.Mail.Attachment(file));
}
If filename
does contain sub-directories then
string fullPath = Path.Combine(@"M:\", filename + ".*");
foreach (string file in Directory.GetFiles(Path.GetDirectoryName(fullPath), Path.GetFileName(fullPath)))
{
yourMailMessage.Attachments.Add(new System.Net.Mail.Attachment(file));
}