I am doing Confirmation mail sent to the register following with this URL
http://blogs.microsoft.co.il/blogs/shair/archive/2011/12/06/email-confirmation-asp-net-mvc-web-application.aspx#comments
but i am getting errors.Can anyone help me.
message.Subject = "Please Verify your Account";
MailBody.Append("<html><table cellpadding='0' cellspacing='0' width='100%' align='center'>" + "<tr><td><p>Dear " + user.UserName+ "</p><br>");
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'> " + verifyUrl + "+"</span> to complete your registration.<br>);
You are missing quotes in your second append. The script highlighter even shows the error.
If you want double quotes within a string it needs to be escaped, e.g. \"
So your second appending should be something like this
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'><a href=\""
+ verifyUrl + "\" target=\"http://localhost:51819\">"
+ verifyUrl + "</a></span> to complete your registration.<br>");
Your New line in constant is due to the fact you're breaking the line without telling the compiler that you want a second line.
There is 3 ways you can fix this:
don't break the line
escape every special character
use # sign to do what you want
As an example:
StringBuilder sb = new StringBuilder();
sb.Append("<html><table cellpadding='0' cellspacing='0' width='100%' align='center'>");
sb.Append("<tr><td><p>Dear " + user.UserName+ "</p><br>");
sb.Append("To verify your account, please click the following link:<span style='font-weight:bold;'>");
sb.Append("<a href='" + verifyUrl + "' target='http://localhost:51819'>" + verifyUrl + "</a></span> to complete your registration.<br>");
MailBody.Append(sb.ToString());
You also need to avoid using a mix of single and double quotes inside a string, the idea is to only use single quotes inside and use double quotes to delimit the string.
You can also use the # in front of a string and you can then break the line like this:
MailBody.Append(
String.Format(
#"<html>
<table cellpadding='0' cellspacing='0' width='100%' align='center'>
<tr>
<td>
<p>Dear {0}</p>
To verify your account, please click the following link:
<span style='font-weight:bold;'>
<a href='{1}'>{1}</a>
</span> to complete your registration.
</td>
</tr>
</table>
</html>", user.UserName, verifyUrl));
I also used StringBuilder to avoid having variables inside the template, as it makes it way more simple to see and edit.
And last, but not least, you should know a little bit more about HTML ... there is no such thing as target="http://localhost:51819"...
Your second MailBody.Append is all messed up
MailBody.Append("To verify your account, please click the following link:<span style='font-weight:bold;'> " + verifyUrl + "</span> to complete your registration.<br>");
Related
How to write xpath for the below HTML:
<span id="filename_548948">Test DC Email </span>
The following xpath doesn't seem to work:
Driver.FindElement(By.XPath(".//span[text() = '" + nameOfEmail + "']")).Click();
The solution depends on what the string nameOfEmail contains.
You have an xpath query on exact text. Meaning every character should be the same in the search as on the webpage.
So if string nameOfEmail = "Test DC Email "
It will search properly.
Also, losing the . in front of the // might help
As per the HTML you have shared you can use the following xpath :
//with a constant string
Driver.FindElement(By.XPath("//span[starts-with(#id,'filename_') and contains(normalize-space(), 'Test DC Email')]")).Click();
//with a variable string
Driver.FindElement(By.XPath("//span[starts-with(#id,'filename_') and contains(normalize-space(), '" + nameOfEmail + "')]")).Click();
I'm trying to read through a file and look for this tag
,<table name="File">,
i've read a bunch and everyone tells me to use #""" or \" to accept the double quotes in the middle of the string, but what it does is turns my string into this. <table name=\"File\"> and it still doesn't work because thats not how it is in the file. examples:
string tblName = " <table name="+#"""File"""+">";
string tblName = " <table name=\"File\">";
Nothing seems to work. It just addes the \ into the string and i can't replace it because it removes the quotes. Any suggestions?
Thanks
string tblName = " <table name="+#"""File"""+">";
try
{
// Only get files that begin with the letter "c."
string[] dirs = Directory.GetFiles(#"C:\Users\dylan.stewart\Desktop\Testing\", "*.ism");
//Console.WriteLine("The number of files starting with c is {0}.", dirs.Length);
foreach (string dir in dirs)
{
foreach( string line in File.ReadLines(dir))
if(line.Contains(tblName))
{
Console.WriteLine(dir);
}
//Console.WriteLine(dir);
}
}
The above methods for adding " into a string are correct. The issue with my OP is i was searching for a specific amount of white space before the tag. I removed the spaces and used the mentioned methods and it is now working properly. Thanks for the help!
string tblName = "<table name=" + '"' + "File" + '"' + ">";
should work since the plus sign concatenate
It should be either
string tblName = #" <table name=""File"">";
or
string tblName = " <table name=\"File\">";
No need for concatenation. Also what do you mean "it still doesn't work"? Just try Console.Write() and you'll see it ok. If you mean the backslashes are visible while inspecting in debugger then it's supposed to be that way
B
I write a small program in c# which is send datas to a blog platform.
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" />";
This is working for me right, i got the result in my blog.:
<img src="http://*************.com/wp-content/uploads/2014/06/ss.jpg" />
But i would like put after the ss.jpg the next.: style="display:none"
If i tried make this.:
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" + "style="display:none"" />";
Its not working. ( would like hide the image.)
I need, the end result like this link.:
<img src="http://************/wp-content/uploads/2014/06/ss.jpg" style="display:none"/>
Can somebody help me?
Thank you
There is no string interpolation required as style="display:none;" is being output as is - it is not dependant on any condition or variable in your code therefore this should work:
post.Body = postContent + "<br><img src=\"" + linkToImage + "\" style=\"display: none;\" />";
I am trying to format a string to add spaces in between the strings in c#.
summary.AppendFormat(" {0} {1}: {2}{3}</br> ", item.FirstName, item.LastName, item.Completed ? item.Summary : "not completed", item.Schedule == DateTime.MinValue ? "" : " (" + DateTime.ToShortDate(item.Schedule, user) + ")");
This should render in the HTML page as
First Round Suri Narayanan: recommend (3/2/2012)
but i am seeing this as like below in html page
First Round</br> Suri Narayanan: recommend (3/2/2012)</br>
if i edit the same using firebug, say if i put some space, then its getting formatted well and good.
Please let me know your comments on this.
You should use Literal like below.
<asp:Literal ID="Literal" runat="server" Mode="PassThrough"></asp:Literal>
Literal.text = "Your text"
I have below code behind in c#
if (Session["cmpDictionaryTitle"]!= null)
{
downloadLinks.Text += #"<li><a onclick='pageTracker._trackEvent('dictionary', 'spanish');' target ='_blank' href=" + Session["cmpDictionaryTitle"] + ">" + GetResourceString("c_DictionaryPDFName") + "</a></li>";
}
I am trying to make below <a> link as shown below:
<li><a target ="_blank" href="/spa/Images/Diccionario_tcm25-18044.pdf" onclick="pageTracker._trackEvent('dictionary', 'spanish');">Diccionario de Español-Inglés GRATIS</a></li>
However my c# code is generating below output when html page get renders, the reason is that I am not able to put proper quotes in my code behind.
<li><a );="" spanish="" ,="" dictionary="" onclick="pageTracker._trackEvent(" href="/spa/Images/Diccionario_tcm25-18044.pdf" target="_blank">Diccionario de Español-Inglés GRATIS</a></li>
Can you please suggest how can I achieve above result in code behind.
Thanks & Best Regards
To use a double-quote in a string built in code, either:
Escape the double-quote character
like this: "\"".
Escape the double-quote character like this:
"""" (when using # to create a verbatim
string literal).
Examples:
// These are both rendered as <a target="_blank" />
Response.Write("<a target =\"_blank\" />");
Response.Write(#"<a target =""_blank"" />");
Here's your original code using backslash-escaped double-quotes for all the attributes (I've chosen the first approach and removed the leading #):
if (Session["cmpDictionaryTitle"]!= null) {
downloadLinks.Text += "<li><a onclick=\"pageTracker._trackEvent('dictionary', 'spanish');\" target =\"_blank\" href=\"" + Session["cmpDictionaryTitle"] + "\">" + GetResourceString("c_DictionaryPDFName") + "</a></li>";
}
Finally, I recommend reading Jon Skeet's excellent article "Strings in .NET and C#."
<a
onclick="pageTracker._trackEvent('dictionary', 'spanish');"
target ="_blank"
href="<%= Server.HtmlEncode((string)Session["cmpDictionaryTitle"]) %>">
<%= Server.HtmlEncode(GetResourceString("c_DictionaryPDFName")) %>
</a>
UPDATE:
You could also build tags using XElement:
var tag = new XElement("li",
new XElement("a",
new XAttribute("onclick", "pageTracker._trackEvent('dictionary', 'spanish');"),
new XAttribute("target", "_blank"),
new XAttribute("href", Session["cmpDictionaryTitle"]),
new XText(GetResourceString("c_DictionaryPDFName"))
)
);
downloadLinks.Text += tag.ToString();
I resolved the above issue with below code:
downloadLinks.Text = string.Format("<li> <a target=\"_blank\" href=\"{0}\" onclick=\"pageTracker._trackEvent('dictionary','spanish');\">{1}</a> </li>",Session["cmpPDFLink"],GetResourceString("c_DictionaryPDFName"));
Cheers!
Your first example is using single quotes for the attribute quotes, and within the value itself, so just change one of them to use double quotes, e.g.:
<a onclick="pageTracker._trackEvent('dictionary', 'spanish');" ...