Formatting an HTML Table - c#

I have a C# application that formats a list into a HTML table which is then sent as an e-mail through Outlook.
The issue I have is rather simple but I cannot resolve. I just want to change the font size of the whole table. No matter what I do the font size does not change. My code is below and I'm aware its not pretty!
string htmlHeader = "<table><font-size=3;><tr><th align='left'>Sedol</th><th> </th><th align='left'>Name</th><th> </th><th text-align:left>Ex Date</th><th> </th><th align='left'>Dividend Type</th><th> </th><th align='left'>Dividend Contribution</th><th> </th><th align='left'>Dividend Value</th><th> </th><th align='left'>Currency</th><th> </th><th align='left'>Country of Incorp</th><th> </th></tr>";
string msgBody = htmlHeader;
for (int i = 0; i < bbergList.Count; i++)
{
string caText = "<tr><td>" + bbergList[i].Sedol + "</td><td> </td><td>"
+ bbergList[i].Name + "</td><td> </td><td>"
+ bbergList[i].dtEx.ToString("dd-MMM-yy") + "</td><td> </td><td>"
+ bbergList[i].DividendType + "</td><td> </td><td>"
+ bbergList[i].DividendValue.ToString("#,0.####") + "</td><td> </td><td>"
+ bbergList[i].DividendAmount.ToString("#,0.####") + "</td><td> </td><td>"
+ bbergList[i].DivCurrency + "</td><td> </td>"
+ bbergList[i].CountryInCorp + "</td><td> </td></tr>";
}
StringBuilder sbFinish = new StringBuilder();
msgBody = sbFinish.Append(msgBody).Append("</font></table>").ToString();

You can use something like this:
<table style="font-size:14px">
you can set the font size to whatever you want.
For a row:
<tr style="font-size:14px">
For a column:
<td style="font-size:14px">

Don't know whether you tried to format your text with C#, but as you want to publish it as html code, I would suggest to use html tags to format:
You can find different examples for formatting text like subscript etc. here:
http://www.w3schools.com/html/html_formatting.asp
And if you want to change color, this example could help:
http://www.w3schools.com/tags/att_font_color.asp
from obove site:
<font color="color_name|hex_number|rgb_number">
Use <font color="red">This is some text!</font> to get red colored font.
Best regards,
Marcus

Related

c# textbox-as-filename problems

I have been trying to make a program and it saves mechanics invoices. So I have got this far;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/thing.doc");
which saves the word doc in a folder that is specified by the registration of the bike - this works fine. but what I really want is the date to be used as a filename...I couldn't figure that out, so I made a date label and plan on using the text from it as the filename instead (I know, its a long way round...but it works). Anyways, I have tried;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text + ".doc");
this was an "invalid filename"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/label19.Text.doc");
this saved it as "label19.Text.doc"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text, ".doc");
This threw the error "(DISP_E_TYPEMISMATCH)"
All I need to do is get label19 text to work as a filename with a .doc extension...or another way of getting the date as a filename
If you need to use current date as file name then you can use:
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yyyy") + ".doc")
Generate the file name in an string variable:
string filename = "C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yy");
and then pass it to SaveAs2 method:
oWord.Application.ActiveDocument.SaveAs2(filename, ".doc");

C# link write fault (html)

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;\" />";

Pasting Data into excel file correctly from textbox

foreach (string TempSize in sizeArr)
{
txtResult.Text += store + "\t" + attributeSet + "\t" + configurableAttri + "\t" + type + "\t" + (ID + "_" + TempColour + TempSize) + "\n";
}
I am trying to generate Multiple Rows that i can use to paste into excel file. "\n" doesn't seem to show on the "new line" of the textbox.
I tried manually doing "\n" aka shift+enter and copy paste the 3 rows into excel, Excel place a empty space between each of them, anyway to remove that problem too?
Thanks in advance!
Problem Fixed with "\r\n" instead of "\n" hat's how Windows controls represent newlines

ConfirmationMail

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>");

adding space and new line in html editor asp.net ajax

I want to insert blank characters in a string move to next line and align right in Html editor ajax control and it should be hardcoded in my below code .
My code is
Editor1.Content = "No. J/" + DropDownList3.SelectedItem + "-" + TextBox1.Text + "-" + tyear + "/" + " " + "/" + year + DateTime.Now.Day+"/"+DateTime.Now.Month+"/"+DateTime.Now.Year;
What i want is
i want 5 blank spaces after
....+ tyear + "/" + "....
Move to next/new line after
....." + "/" + year +....
Apply Align left to this entire
content
To add blank spaces to the keyword. Normal blank spaces will be ignored as whitespace by the HTML parser.

Categories