locked
Crating a vCard wit asp RRS feed

  • Question

  • User-1634117515 posted

    hi, 

    I'm trying to create a vCard with a picture but when the vCard ist created it has not the picture, how Can I solve this?

    Here is the code I'm using.

     public static vCard card(Director d)
    
        {
            var myCard = new vCard()
            {
                FirstName = d.Nombre,
                LastName = String.Empty,
                Organization = "Ritch Mueller",
                JobTitle = "Lic.",
                StreetAddress = "Pegregal 24 Piso 10, Molino del Rey, 11040",
                City = "CDMX",
                CountryName = "Miguel Hidalgo",
                Phone = d.Directo,
                Mobile = d.Movil,
                Email = d.Correo,
                HomePage = "www.ritch.com.mx"
            };
    
            myCard.Image = File.ReadAllBytes(@"J:\Images\Usuarios\aalpizar.png");
    
            using (var file = File.OpenWrite("D:\\me.vcf"))
    
            using (var writer = new StreamWriter(file))
    
            {
    
                writer.Write(myCard.ToString());
    
            }
            return myCard;
        }

    Thursday, June 13, 2019 5:36 PM

All replies

  • User61956409 posted

    Hi markdirtyboy,

    create a vCard with a picture but when the vCard ist created it has not the picture, how Can I solve this?

    Please tell us which c# library/NuGet package you are using to create vCard, so that we can help reproduce and troubleshoot the issue better.

    With Regards,

    Fei Han

    Friday, June 14, 2019 2:27 AM
  • User-1038772411 posted

    Hello markdirtyboy,

    Try with this example pattern , I hope this will help you

    var vCard = new StringBuilder();
    
            vCard.Append("BEGIN:VCARD");
            vCard.AppendLine();
            vCard.Append("VERSION:2.1");
            vCard.AppendLine();
    
            // Name
            vCard.Append($"N:  {model.sLastname};{model.sFirstname};");
            vCard.AppendLine();
    
            vCard.Append($"FN:{model.sFirstname} {model.sLastname}");
            vCard.AppendLine();
    
            // Company
            vCard.Append("ORG:");
            vCard.Append(model.sCompanyName);
            vCard.AppendLine();
    
            // Job Title
            vCard.Append("TITLE:");
            vCard.Append(model.sJobTitle);
            vCard.AppendLine();
    
            // Image
            FileModel file = FileModel.getByGuid(model.sProfilePicGuid);
            vCard.Append($"PHOTO;ENCODING=BASE64;TYPE={file.sFileType}:");
            vCard.Append(Convert.ToBase64String(file.FileData));
            vCard.AppendLine(string.Empty);
            vCard.AppendLine();
    
            // Tel
            vCard.Append("TEL");
            vCard.Append(";");
            vCard.Append("WORK");
            vCard.Append(";");
            vCard.Append("VOICE:");
            vCard.Append(model.sCompanyPhone);
            vCard.AppendLine();
    
            // Cell
            vCard.Append("TEL");
            vCard.Append(";");
            vCard.Append("CELL");
            vCard.Append(";");
            vCard.Append("VOICE:");
            vCard.Append(model.sPhoneNumber);
            vCard.AppendLine();
    
            // Email
            vCard.Append("EMAIL");
            vCard.Append(";");
            vCard.Append("PREF");
            vCard.Append(";");
            vCard.Append("INTERNET:");
            vCard.Append(model.sEmail);
            vCard.AppendLine();
    
            // Web site
            vCard.Append("URL");
            vCard.Append(";");
            vCard.Append("WORK:");
            vCard.Append(model.sWebsiteUrl);
            vCard.AppendLine();
    
            // Address
            string address = model.sAddress.Replace("\n"," ");
            vCard.Append($"ADR; WORK; PREF:; ; {address}; ; ; ; ");
            vCard.AppendLine();
    
            // End
            vCard.Append("END:VCARD");
            string result = vCard.ToString();

    If you want to output in IOS devices ,

    Use vCard.AppendLine() instead of vCard.Append("\n") because IOS devices uses "\r" instead of "\n".

    vCard.AppendLine() produces "\r\n". That way it will work in Windows and IOS (linux)

    Thank You.

    Friday, June 14, 2019 7:33 AM