Sign In  Sign Up Live-Chat

hyperlinks with mergefields

Last post 07-04-2008, 9:56 AM by alexey.noskov. 1 replies.
Sort Posts: Previous Next
  •  07-04-2008, 9:36 AM 134372

    hyperlinks with mergefields

    hi,
    i am using mergefields and executewithregions option with mergefields.

    now my problem is i have two mergefiels (ImageLink) and (WebsiteUrl) how to insert hyperlinks to merge fields with hyperlinks
     
  •  07-04-2008, 9:56 AM 134375 in reply to 134372

    Re: hyperlinks with mergefields

    Attachment: Present (inaccessible)

    Hi

     

    Thanks for your inquiry. You can use MergeField event handler to achieve this. For example see the following code and attached documents:

     

    public void Test275()

    {

        string[] names = { "ImageLink", "WebsiteUrl" };

        string[] values = { "http://philip9876.files.wordpress.com/2007/10/nuclear-explosion.jpg", "http://www.aspose.com" };

        //Open template

        Document doc = new Document(@"Test275\in.doc");

        //And MergedField event handler

        doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField275);

        //Execute mail merge

        doc.MailMerge.Execute(names, values);

        //Save document

        doc.Save(@"Test275\out.doc");

    }

     

    void MailMerge_MergeField275(object sender, MergeFieldEventArgs e)

    {

        if (e.FieldName == "ImageLink" || e.FieldName == "WebsiteUrl")

        {

            //Create DocumentBuilder

            DocumentBuilder builder = new DocumentBuilder(e.Document);

            //Move to mergefield

            builder.MoveToMergeField(e.FieldName);

            //Insert hyperlink

            builder.Font.Underline = Underline.Single;

            builder.Font.Color = Color.Blue;

            builder.InsertHyperlink(e.FieldValue.ToString(), e.FieldValue.ToString(), false);

        }

    }

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML