附件c#的帮助 [英] Help with Attachment c#
本文介绍了附件c#的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我编写了以下代码(使用摘要),并且需要提取特定文件夹中具有.txt文件扩展名的任何文件.我尝试了许多代码片段,但无法正确完成.
请有人可以修改或帮助我:confused:
Hi I have written the following code (using snippets) and need to pick up any file that has the .txt file extension in a specific folder. I have tried many code snippets and just cant get it right.
Please can someone modify or help me:confused:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows;
using System.Web.Mail;
namespace TfL
{
class Program
{
static void Main(String[] args)
{
System.IO.FileInfo info = new System.IO.FileInfo("c:\\Source\\LNS_IS.txt");
if (File.Exists("c:\\Source\\LNS_IS.txt") && (info.Length > 0))
{
MailMessage oMsg = new MailMessage();
oMsg.From = "Happy@test.com";
oMsg.To = "246@gmail.com";
oMsg.Subject = "Unattended Mailbox do not reply";
oMsg.BodyFormat = MailFormat.Html;
// ADD AN ATTACHMENT.
String sFile = @"C:\Source\LNS_IS.TXT";
MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);
oMsg.Attachments.Add(oAttch);
//SMTP server.
SmtpMail.SmtpServer = "vmtestmac";
SmtpMail.Send(oMsg);
oMsg = null;
oAttch = null;
//move the file now email is sent
string sourceFile = @"C:\Source\LNS_IS.txt";
string destinationFile = @"C:\Archive\LNS_IS.txt";
System.IO.File.Move(sourceFile, destinationFile);
//shows message for testing
global::System.Windows.Forms.MessageBox.Show("sending File Exists ");
}
else
{
MailMessage oMsg = new MailMessage();
oMsg.From = "Happy@test.com";
oMsg.To = "246@gmail.com";
oMsg.Subject = "Unattended Mailbox do not reply";
oMsg.BodyFormat = MailFormat.Html;
//SMTP server.
SmtpMail.SmtpServer = "vmtestmac";
SmtpMail.Send(oMsg);
oMsg = null;
//shows message for testing
global::System.Windows.Forms.MessageBox.Show("sending file not exist");
}
//checking if file has any data
if (info.Length < 1)
{
//move the file
string sourceFile = @"C:\Source\LNS_IS.txt";
string destinationFile = @"C:\Baddata\LNS_IS.txt";
System.IO.File.Move(sourceFile, destinationFile);
}
}
}
}
推荐答案
尝试一下:
Try this:
DirectoryInfo dirInfo = new DirectoryInfo(@"c:\MyDir");
string[] files = dirInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly);
感谢约翰,然后我使用这段代码得到了两个错误:-
' System.IO.DirectoryInfo.GetFiles(string,System.IO.SearchOption)'的最佳重载方法匹配有一些无效的参数
和
参数"2":无法从布尔"转换为"System.IO.SearchOption"
任何想法:困惑:
Thanks John then I use this code i get two errors:-
best overloaded method match for 'System.IO.DirectoryInfo.GetFiles(string, System.IO.SearchOption)' has some invalid arguments
and
Argument ''2'': cannot convert from ''bool'' to ''System.IO.SearchOption''
Any Ideas:confused:
再次感谢约翰,但我仍然遇到错误:-
无法隐式转换类型' System.IO.FileInfo []'.到' string []'
:(
Thanks Again John but I still got an error:-
Cannot implicitly convert type 'System.IO.FileInfo[]' to 'string[]'
:(
这篇关于附件c#的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文