Renderizar Hiperlinks com Estilo Personalizado
Contents
[
Hide
]
Pode haver momentos em que você precisa gerar hiperlinks com um estilo específico com base nos requisitos da sua aplicação. Para isso, Aspose.Email fornece HyperlinkRenderingCallback. Você pode passar o HyperlinkRenderingCallback como um parâmetro de MailMessage.GetHtmlBodyText.
O seguinte trecho de código mostra como usar HyperlinkRenderingCallback para gerar hiperlinks usando seu próprio 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; | |
} |
Os métodos RenderHyperlinkWithHref e RenderHyperlinkWithoutHref têm a intenção de demonstrar a renderização de hiperlinks e não são destinados ao uso em produção.