“类”,“结构”或“接口成员”声明中的“令牌”无效

时间:2012-10-26 11:23:56

标签: c# asp.net

我正在尝试通过asp.net webapp发送文件。

我收到以下错误8次,我的代码中包含不同的符号: 类,结构或接口成员声明中的标记'='无效

感觉我错过了一个功能,但我不确定。

这是我的整个.cs类代码:

// A namespace does not directly contain members such as fields or methods

namespace vCardGenerator.Website
{
public partial class SendvCard
{
    public void Mailvcard()
    {

//Class SendMail.cs
/*          
                string txtFile = txtFile.Text;
                string strDir = "C:\\local\\vCardGenerator.Website"; //temp save location
                string strFilename = Path.GetFileName(txtFile.PostedFile.FileName);

                txtFile.PostedFile.SaveAs(strDir + strfilename);
                mail.Attachments.Add(new MailAttachment(strDir + strFilename));
                //Error with MailAttachment/MailAddress??

                MailAddress;
                if (useOverrideIfDebug && AppSettings.EmailToAddressOverride.Length > 0)
                    to = new MailAddress(AppSettings.EmailToAddressOverride, recipient.DisplayName);
                else
                    to = recipient;

                Exception error = null;
                foreach (string server in AppSettings.SmtpServers)
                {   

*/
Mailer smtp = new Mailer(server);
}
    smtp.AddAttachment = (@"C:\\Desktop\\FirstName_FamilyName.vcf");
    smtp.FromAddress = "email";
    smtp.Subject = "vCard";
    smtp.MailBody = "vCard is added as file";
    smtp.AddRecipient = txtMail.Text;

//to = txtMail.Text;
    try
    {
        SmtpMail.Send();
    }
    catch (exception ex)
    {
        Responds.Write("Exception Occured:   " + ex);
    }
// Responds.Write("FAiled, try again please!")
    finally
    {
        Responds.Write("De vCard has been sent succesfully!");
    }
// delete vcard
    //  File.Delete(@"C:\\Bureaublad\\") + ("FirstName_LastName.vcf");
        File.Delete(strDir + strFilename);
}

我是这方面的初学者,并希望得到一个如何解决这个问题的暗示,因为谷歌再次让我失望,我正在搜索半天。 但你必须在某个地方开始吗?

先谢谢,

4 个答案:

答案 0 :(得分:1)

你太早关闭这个方法所以后面的所有代码都是在类中:

Mailer smtp = new Mailer(server);

}

删除尾随}并确保它在

之后

File.Delete(strDir + strFilename);

答案 1 :(得分:1)

你在这一行下有一个近距离支撑:

Mailer smtp = new Mailer(server);

答案 2 :(得分:0)

删除评论以揭示真相:

namespace vCardGenerator.Website
{
public partial class SendvCard
{
    public void Mailvcard()
    {

Mailer smtp = new Mailer(server);
} // <===== THIS ENDS THE METHOD
    smtp.AddAttachment = (@"C:\\Bureaublad\\FirstName_FamilyName.vcf");
    smtp.FromAddress = "email";
    smtp.Subject = "vCard";
    smtp.MailBody = "In de bijlage vindt u de vCard";
    smtp.AddRecipient = txtMail.Text;

这意味着所有:

    smtp.AddAttachment = (@"C:\\Bureaublad\\FirstName_FamilyName.vcf");
    smtp.FromAddress = "email";
    smtp.Subject = "vCard";
    smtp.MailBody = "In de bijlage vindt u de vCard";
    smtp.AddRecipient = txtMail.Text;

属于班级。

答案 3 :(得分:0)

在块注释后删除花括号两行。