コード例 #1
0
ファイル: Helper.cs プロジェクト: xxjeng/nuxleus
        /// <summary>
        ///     Writes a card, then reads it back and compares fields.
        /// </summary>
        public static void CycleStandard21(vCard card)
        {

            if (card == null)
                throw new ArgumentNullException("cycle");

            // Create a memory stream to hold the contents of the card.

            MemoryStream stream = new MemoryStream();

            StreamWriter textWriter = new StreamWriter(stream);

            // Create a standard vCard writer and export the
            // card data to the stream.

            vCardStandardWriter writer = new vCardStandardWriter();
            writer.Write(card, textWriter);
            textWriter.Flush();

            // Reset the stream (back to its beginning), then
            // create a stream reader capable of reading text
            // lines from the stream.

            stream.Seek(0, SeekOrigin.Begin);
            StreamReader streamReader = new StreamReader(stream);

            vCardStandardReader standardReader = new vCardStandardReader();
            vCard reloaded = standardReader.Read(streamReader);

            Equals(card, reloaded);

        }
コード例 #2
0
ファイル: Default.aspx.cs プロジェクト: xxjeng/nuxleus
    /// <summary>
    ///     Executed when the Submit button is clicked.
    /// </summary>
    protected void SubmitButton_Click(object sender, EventArgs e)
    {

        vCard card = new vCard();

        // Simple properties

        card.AdditionalNames = AdditionalNames.Text;
        card.FamilyName = FamilyName.Text;
        card.GivenName = GivenName.Text;
        card.NamePrefix = NamePrefix.Text;
        card.NameSuffix = NameSuffix.Text;
        card.Organization = Organization.Text;
        card.Role = Role.Text;
        card.Title = Title.Text;

        // ---------------------------------------------------------------
        // Email Addresses
        // ---------------------------------------------------------------
        // A vCard supports any number of email addresses.

        if (!string.IsNullOrEmpty(WorkEmail.Text))
        {
            card.EmailAddresses.Add(
                new vCardEmailAddress(WorkEmail.Text));

        }

        // ---------------------------------------------------------------
        // Notes
        // ---------------------------------------------------------------
        // The vCard specification allows for multiple notes, although
        // most applications seem to support a maximum of one note.

        if (Note.Text.Length > 0)
        {
            card.Notes.Add(new vCardNote(Note.Text));
        }


        // ---------------------------------------------------------------
        // Phones
        // ---------------------------------------------------------------
        //
        // A vCard supports any number of telephones.  Each telephone can
        // have a different type (such as a video phone or a fax) and a
        // purpose (e.g. a home number or a work number).

        if (!string.IsNullOrEmpty(WorkPhone.Text))
        {
            card.Phones.Add(
                new vCardPhone(WorkPhone.Text, vCardPhoneType.WorkVoice));
        }

        if (!string.IsNullOrEmpty(WorkFax.Text))
        {
            card.Phones.Add(
                new vCardPhone(WorkFax.Text, vCardPhoneType.WorkFax));
        }


        // ---------------------------------------------------------------
        // Web Sites
        // ---------------------------------------------------------------

        if (WorkWebSite.Text.Length > 0)
        {
            card.WebSites.Add(
                new vCardWebSite(WorkWebSite.Text, vCardWebSiteType.Work));
        }

        // ---------------------------------------------------------------
        // Nicknames
        // ---------------------------------------------------------------

        string[] nicklist = Nicknames.Text.Split(new char[] { ',' });
        foreach (string nick in nicklist)
        {
            if (nick.Length > 0)
                card.Nicknames.Add(nick);
        }

        // The vCard object has been populated.  The rest of
        // the code generates the vCard file format and exports
        // it to the response stream.

        Response.ContentType = "text/x-vcard";

        // The "content-disposition" is a special HTTP header
        // that tells the web browser how to interpreted the
        // output.  In this case, the browser is informed the
        // content should be treated as an attachment with
        // a default filename.  This should cause the browser
        // to display a dialog box to save the vCard (instead
        // of displaying the vCard as inline text).

        Response.AppendHeader(
            "content-disposition", "attachment;filename=vCard.vcf");

        vCardStandardWriter writer = new vCardStandardWriter();

        writer.EmbedInternetImages = false;
        writer.EmbedLocalImages = true;
        writer.Options = vCardStandardWriterOptions.IgnoreCommas;

        writer.Write(card, Response.Output);
        Response.End();

    }