locked
Setting Hyperlinks & Formatting in Script task RRS feed

  • Question

  • How to set hyperlink to a text which will is actually appended to original texts. 

    The texts are combined for framing body content of a mail.

    my code goes like this 

    ....

    StringBuilder sb = new StringBuilder();

    String Body;

    sb.Append("The following are the values").AppendLine();

    sb.Append("Values .....").AppendLine();

    sb.AppendLine();

    sb.Append("Thanks,").AppendLine();

    sb.Append("Amin - Team"); --> Here i need to link our website address to 'Admin - Team'. Also need to display this text in blue color

    Body = sb;

    .........

    While the mail is sent the user should be able to click on 'Admin - team' to access the website. Please let me know how i can change the color & set the website address as hyperlink ?

    Thanks !


    --------------------------- Radhai Krish | Golden Age is no more far | --------------------------

    Friday, March 8, 2013 8:09 AM

Answers

  • Hi radha,

    Add The below Code

    sb.Append("<a href="your link here" alt= "Admin team">Amin - Team</a>");

    and set mail.format as HTML while sending mail.

    Regards

    Naveen

    • Marked as answer by Radhai Friday, March 8, 2013 11:31 AM
    Friday, March 8, 2013 8:32 AM
  • Hi Radha,

    Use backslash, rather than forward slash, use below code

    sb.Append("<a href='https:\\ourdomainsiteadress' alt= 'Admin team'>Amin - Team</a>");

    Regards

    Naveen


    • Edited by Naveen Kumar K.R Friday, March 8, 2013 10:33 AM
    • Marked as answer by Radhai Friday, March 8, 2013 11:31 AM
    Friday, March 8, 2013 10:32 AM
  • No we cannot use HTML format only for last line because the content which is last line contains HTML tags i mean <a></a> and only that doesn't work. But what you can do is add <br/> at the end of each line so that it will break the line. I mean

    sb.Append("Your value <br/>");

    Regards

    Naveen



    • Edited by Naveen Kumar K.R Friday, March 8, 2013 11:00 AM
    • Marked as answer by Radhai Friday, March 8, 2013 11:31 AM
    Friday, March 8, 2013 10:58 AM
  • Then what you can do is to replace new line character with <br/>

    sb.Append(values.Replace(System.Environment.NewLine,"<br/>"))

    if the above code doesn't work then

    sb.Append(values.Replace("\n",br/>"))

    Regards

    Naveen



    • Edited by Naveen Kumar K.R Friday, March 8, 2013 12:10 PM
    • Marked as answer by Radhai Friday, March 8, 2013 1:26 PM
    Friday, March 8, 2013 11:59 AM

All replies

  • Hi radha,

    Add The below Code

    sb.Append("<a href="your link here" alt= "Admin team">Amin - Team</a>");

    and set mail.format as HTML while sending mail.

    Regards

    Naveen

    • Marked as answer by Radhai Friday, March 8, 2013 11:31 AM
    Friday, March 8, 2013 8:32 AM
  • Hi radha,

    Add The below Code

    sb.Append("<a href="your link here" alt= "Admin team">Amin - Team</a>");

    and set mail.format as HTML while sending mail.

    Regards

    Naveen

    Thanks Naveen, I'll try that and update the result. 

    Also, in that way will the font color automatically changes to that default blue ? (just curious that if the mail format set to HTML the text will appear blue color.)

    Else could you please help in that too ? Thanks a lot!


    --------------------------- Radhai Krish | Golden Age is no more far | --------------------------

    Friday, March 8, 2013 8:56 AM
  • yes, font colour will automatically change to blue and will be underlined, if not let me know i can help you out,

    Regards

    Naveen


    Friday, March 8, 2013 9:10 AM
  • yes, font colour will automatically change to blue and will be underlined, if not let me know i can help you out,

    Regards

    Naveen


    Thanks Naveen !

    Now i face diff problem in pasting the link inside,

    sb.Append("<a href="https://ourdomainsiteadress" alt= "Admin team">Amin - Team</a>");

    Here in the above the '//' is treated as line for commenting and the rest of the syntax turns green color. 

    Also the second " double quotes immediately before https marks the text falling before it as brown which is expected to get for the whole line code.

    I tried removing, putting extra double quotes but none helped me ..


    --------------------------- Radhai Krish | Golden Age is no more far | --------------------------

    Friday, March 8, 2013 10:30 AM
  • Hi Radha,

    Use backslash, rather than forward slash, use below code

    sb.Append("<a href='https:\\ourdomainsiteadress' alt= 'Admin team'>Amin - Team</a>");

    Regards

    Naveen


    • Edited by Naveen Kumar K.R Friday, March 8, 2013 10:33 AM
    • Marked as answer by Radhai Friday, March 8, 2013 11:31 AM
    Friday, March 8, 2013 10:32 AM
  • Hi Radha,

    Use backslash, rather than forward slash, use below code

    sb.Append("<a href='https:\\ourdomainsiteadress' alt= 'Admin team'>Amin - Team</a>");

    Regards

    Naveen


    Naveen Wonderful That did work ! Thank you..

    But HTML format made the mail content to club together irrespective of the line spaces added between the header lines and the values provided. is there way that we can use the HTML format only to the last line (Admin - team) ? 


    --------------------------- Radhai Krish | Golden Age is no more far | --------------------------

    Friday, March 8, 2013 10:46 AM
  • No we cannot use HTML format only for last line because the content which is last line contains HTML tags i mean <a></a> and only that doesn't work. But what you can do is add <br/> at the end of each line so that it will break the line. I mean

    sb.Append("Your value <br/>");

    Regards

    Naveen



    • Edited by Naveen Kumar K.R Friday, March 8, 2013 11:00 AM
    • Marked as answer by Radhai Friday, March 8, 2013 11:31 AM
    Friday, March 8, 2013 10:58 AM
  • Thanks a lot Naveen for your assistance !

    Would like to ask in the same email script, i take values from text file.

    The text file will have the values like,

    Test1

    test2

    test3

    now my code is like,

    sb.Append("The following are the values<br/>").AppendLine();

    sb.Append(Values).AppendLine();

    sb.Append("<br/>").AppendLine();

    But my mail shows like,

    The following are the values

    Test1 test2 test3

    Is there a way that i can still make this values appear as like in the text file i.e. row wise ?

    Thanks!


    --------------------------- Radhai Krish | Golden Age is no more far | --------------------------

    Friday, March 8, 2013 11:37 AM
  • are you using any loop in the code to read text file values? can you place the code if possible



    Friday, March 8, 2013 11:41 AM
  • are you using any loop in the code to read text file values? can you place the code if possible

    Yes sure, the following is the model code, ('Sr & Values' included now) UserDetails is the variable holding the text file path and the file name.

    StringBuilder sb = new StringBuilder();

    StreamReader Sr = new StreamReader("DTS.Variables[UserDetails].Value.ToString()") 

    String Values = Sr.ReadToEnd();

    String Body;

    sb.Append("The following are the values <br/>").AppendLine();

    sb.Append(Values).AppendLine();

    sb.Append("<br/>").AppendLine();

    sb.Append("Thanks,<br/>").AppendLine();

    sb.Append("<a href='https:\\ourdomainsiteadress' alt= 'Admin team'>Amin - Team</a>");

    Body = sb;

    ---------------------------------------------------------------------------

    - Thanks !


    --------------------------- Radhai Krish | Golden Age is no more far | --------------------------


    • Edited by Radhai Friday, March 8, 2013 11:53 AM
    Friday, March 8, 2013 11:52 AM
  • Then what you can do is to replace new line character with <br/>

    sb.Append(values.Replace(System.Environment.NewLine,"<br/>"))

    if the above code doesn't work then

    sb.Append(values.Replace("\n",br/>"))

    Regards

    Naveen



    • Edited by Naveen Kumar K.R Friday, March 8, 2013 12:10 PM
    • Marked as answer by Radhai Friday, March 8, 2013 1:26 PM
    Friday, March 8, 2013 11:59 AM
  • Thank you very very much Mr.Naveen !! Its working good :)


    --------------------------- Radhai Krish | Golden Age is no more far | --------------------------

    Friday, March 8, 2013 1:27 PM
  • welcome Radha :)
    Saturday, March 9, 2013 5:36 AM