-2

我正在尝试通过 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

4 回答 4

1

您太早地关闭了该方法,因此之后的所有代码都在类中:

Mailer smtp = new Mailer(server);

}

删除尾随}并确保它在后面

File.Delete(strDir + strFilename);

于 2012-10-26T11:26:16.790 回答
1

您在此行下有一个大括号:

Mailer smtp = new Mailer(server);
于 2012-10-26T11:26:39.407 回答
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;

处于班级水平。

于 2012-10-26T11:27:02.793 回答
0

删除块注释后两行的大括号。

于 2012-10-26T11:27:39.273 回答