Renderizar hiperenlaces con estilo personalizado
Contents
[
Hide
]
Puede haber momentos en los que necesite mostrar hiperenlaces con un estilo específico basado en los requisitos de su aplicación. Para eso, Aspose.Email proporciona HyperlinkRenderingCallback. Puede pasar el HyperlinkRenderingCallback como un parámetro de MailMessage.GetHtmlBodyText.
El siguiente fragmento de código le muestra cómo usar HyperlinkRenderingCallback para mostrar hiperenlaces utilizando su propio estilo personalizado.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static void Run() | |
{ | |
string dataDir = RunExamples.GetDataDir_Email(); | |
var fileName = dataDir + "LinksSample.eml"; | |
MailMessage msg = MailMessage.Load(fileName); | |
Console.WriteLine(msg.GetHtmlBodyText(RenderHyperlinkWithHref)); | |
Console.WriteLine(msg.GetHtmlBodyText(RenderHyperlinkWithoutHref)); | |
} | |
private static string RenderHyperlinkWithHref(string source) | |
{ | |
int start = source.IndexOf("href=\"") + "href=\"".Length; | |
int end = source.IndexOf("\"", start + "href=\"".Length); | |
string href = source.Substring(start, end - start); | |
start = source.IndexOf(">") + 1; | |
end = source.IndexOf("<", start); | |
string text = source.Substring(start, end - start); | |
string link = string.Format("{0}<{1}>", text, href); | |
return link; | |
} | |
private static string RenderHyperlinkWithoutHref(string source) | |
{ | |
int start = source.IndexOf(">") + 1; | |
int end = source.IndexOf("<", start); | |
string text = source.Substring(start, end - start); | |
return text; | |
} |
Los métodos RenderHyperlinkWithHref y RenderHyperlinkWithoutHref están destinados a demostrar la renderización de hiperenlaces y no están destinados para uso en producción.