当我尝试调试代码时,在进入“添加附件”部分时,Watch 2 屏幕中的 ContentDisposition 为我提供了附件的 -1 大小。
这使我的代码跳闸并给我错误消息:
邮件发送失败。
整个代码:
private Attachment createCardAttachment()
{
// Information string
string FamilyName = "FamilyName";
string FirstName = "FirstName";
string MiddleName = "MiddleName";
string Title = "Miss,Mr.";
string Suffix = "suffix(s)";
// string Birthday = "YYYY-MM-DD";
string WorkAddressStreet = "WorkAddressStreet";
string WorkAddressCity = "WorkAddressCity";
string WorkAddressStateProvince = "WorkAddressStateProvince";
string WorkAddressZipPostalCode = "1234 AA";
string WorkAddressCountry = "WorkAddressCountry";
string HomeAddressStreet = "HomeAddressStreet";
string HomeAddressCity = "HomeAddressCity";
string HomeAddressStateProvince = "HomeAddressStateProvince";
string HomeAddressZipPostalCode = "1234 AA";
string HomeAddressCountry = "HomeAddressCountry";
string EmailPersonal = "Person@personaldomain.com";
string EmailWork = "Person@workdomain.com";
string Organization = "Organization";
string WorkPhone = "123-456-7890 ext 321";
string WorkFax = "123-456-7890";
string CellPhone = "123-456-7890";
string HomePhone = "123-456-7890";
string JobTitle = "Programmer";
string WorkURL = "http://www.domain.com";
string ID = Request.QueryString["ID"]; // Database QueryString
// Save vCard Generate Code as .vcf extension
string path = ("C:\\local\\vCardGenerator.Website\\FirstName_LastName.vcf");
// Test attachment send
Attachment attach = null;
MemoryStream ms = new MemoryStream();
// vCard C# Code
using (StreamWriter sw = new StreamWriter(ms))
{
sw.Write("BEGIN:VCARD\r\n");
sw.Write("VERSION:1.0\r\n");
sw.Write("N;LANGUAGE=en-us:{0};{1};{2};{3};{4};;\r\n", FamilyName, FirstName, MiddleName, Title, Suffix);
sw.Write("FN:{0} {1} {2} {3} {4}\r\n", Title, FirstName, MiddleName, Suffix, FamilyName);
sw.Write("ORG:{0}\r\n", Organization, "\r\n");
sw.Write("TEL;WORK;VOICE:{0}\r\n", WorkPhone, "\r\n");
sw.Write("TEL;WORK;FAX:{0}\r\n", WorkFax, "\r\n");
sw.Write("TEL;CELL;VOICE:{0}\r\n", CellPhone, "\r\n");
sw.Write("TEL;HOME;VOICE:{0}\r\n", HomePhone, "\r\n");
sw.Write("TITLE:{0}\r\n", JobTitle, "\r\n");
sw.Write("ADR;INTL;PARCEL;WORK:;;{0}; {1}; {2}; {3}; {4};\r\n", WorkAddressStreet, WorkAddressCity, WorkAddressStateProvince, WorkAddressZipPostalCode, WorkAddressCountry);
sw.Write("ADR;INTL;PARCEL;HOME:;;{0}; {1}; {2}; {3}; {4};\r\n", HomeAddressStreet, HomeAddressCity, HomeAddressStateProvince, HomeAddressZipPostalCode, HomeAddressCountry);
sw.Write("URL;WORK:{0}\r\n", WorkURL);
sw.Write("EMAIL;PREF;INTERNET:{0}\r\n", EmailPersonal);
sw.Write("EMAIL;INTERNET:{0}\r\n", EmailWork);
sw.Write("END:VCARD\r\n");
ContentType ct = new ContentType(MediaTypeNames.Application.Octet);
attach = new Attachment(ms, ct);
// Goes well until here
// Gives the attachment a size of -1
attach.ContentDisposition.FileName = "FirstName_LastName.vcf";
attach.Name = "FirstName_LastName.vcf";
sw.Flush();
sw.Close();
ms.Close();
}
return attach;
}
}
}
具体的:
// Goes well until here
// Gives the attachment a size of -1
attach.ContentDisposition.FileName = "FirstName_LastName.vcf";
任何人都可以向我提供任何信息为什么我的附件大小为-1?
如果需要,愿意提供更多信息/代码。
提前致谢,