Monday, February 23, 2015

HTML Character Entities

Following post will give us an idea how to include character entities in our web pages.

Note : Character entities are case sensitive

I have included following aspx design page tags for your reference.
<form id="form1" runat="server">
<div>
HTML Character Entities. Entity names are case sensitive.

<p>this is &nbsp; space.</p>
<p>this is &amp; ampersand.</p>
<p>this is &lt; less than</p>
<p>this is &gt; greater than</p>
<p>this is &empty; empty</p>
<p>this is &nabla; NABLA</p>
<p>this is &cent; cent</p>
<p>this is &pound; pound</p>
<p>this is &yen; yen</p>
<p>this is &euro; euro</p>
<p>this is &copy; copyright</p>
<p>this is ® register trademark</p>
<p>this is &trade; trademark</p>
<p>this is &prod; pi</p>
<p>this is &sum; summation</p>
<p>this is &epsilon; epsilon<br />
this is &Epsilon; epsilon</p>
<p>this is &delta; Delta<br />
this is &Delta; Delta</p>
<p>this is &alpha; alpha<br />
this is &Alpha; alpha</p>
<p>this is &beta; beta<br />
this is &Beta; beta</p>
<p>this is &gamma; gamma
<br />this is &Gamma; gamma</p>
<p>this is &hearts; hearts<br />
this is &spades; spade<br />
this is &clubs; <br />
this is &diams; diamond</p>

Diacritical Marks to letter k

<p>k&#768;<br />
k&#769;<br />
k&#770;<br />
k&#771;</p>
</div>
</form>
 

 
 
 



After viewing this page in browser, we will see following    
this is   space.
this is & ampersand.
this is < less than
this is > greater than
this is ∅ empty
this is ∇ NABLA
this is ¢ cent
this is £ pound
this is ¥ yen
this is € euro
this is © copyright
this is ® register trademark
this is ™ trademark
this is ∏ pi
this is ∑ summation
this is ε epsilon
this is Ε epsilon
this is δ Delta
this is Δ Delta
this is α alpha
this is Α alpha
this is β beta
this is Î’ beta
this is γ gamma
this is Γ gamma
this is ♥ hearts
this is ♠ spade
this is ♣
this is ♦ diamond 
   
Diacritical Marks to letter k



  
 
 
for more details visit this link for details.

Wednesday, February 18, 2015

Step by Step procedure to create first SSRS repport

SSRS : step by step method to create simple report


  1. Open visual studio 2013 blend.
  2. Select File -> New -> Project
  3. Select Report Server Report Wizard as shown below.


  1. Following dialog box will open


  1. Give name to New DataSource and click on Edit to set connection properties. We are selecting adventureworks database  





 
 
  1. Now the report wizard will show Query builder window. Click on Query Builder.   
Select Edit as Text. Write your desired Query, command Type : Text or stored procdure , command type : StoredProcedure. Run Query to verify result.
 

 
  1. At last set report formatting, like report type tabular or matrix, grouping, paging, etc. Give name to the report and preview your report.
 


Thursday, February 12, 2015

Send Email with attachment - HTML attachment

Note:

While sending email with google SMTP server, we may get following error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

In order to avoid such error -
Go to the link https://www.google.com/settings/security/lesssecureapps and turn on feature access for less secure app.


=========================================================================

Following code will give us an idea how to create an HTML attachment and send it via email.

Step 1:  Create a simple asp.net application and on it's design page add a button control. On the click event of this button control we have to write code to create a HTML file and sent it via email as an attachment.

Step 2: On Button click event, write following code.
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
//html attachment
//1. Format : Head, title , body
string testContent= create_HTML_FILE();
lblHTML.Text = testContent;
//send Email
sendEmail();
lblMail.Text = "check email";
}
catch (Exception)
{
//throw;
}
}

Here create_HTML_FILE(); and sendEmail(); are two user defined methods.


Step 3: create_HTML_FILE();

Now we will write a code to create a HTML file. We are saving this file in project root folder.
private string create_HTML_FILE()
{
string strHTML = "";
try
{
string strHStart = "<HTML>";
string strHEnd = "</HTML>";
string strTitle = "<Title>test title</Title>";
string strHeader = "<H1>This is test Header</H1>";
string strBody = "<Body>this is test body this is test body this is test body this is test body this is test body this is test body </Body>";
strHTML = strHStart + strTitle +strHeader + strBody + strHEnd;
FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"//testKB.html", FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write(strHTML);
sw.Flush();
sw.Close();
fs.Close();
}
catch (Exception)
{
//throw;
}
return strHTML;
}
We can format Body, Header, Title  as per our requirement.
Note that we are saving file in root directory of project AppDomain.CurrentDomain.BaseDirectory
and name of the file is testKB.html



Step 4: sendEmail();

Now Write code to send email with attachment
public void sendEmail()
{
try
{
string toEmail = "to email";
string FromEmail = "from email";
MailAddress maTO = new MailAddress(toEmail);
MailAddress maFROM = new MailAddress(FromEmail);
MailMessage mm = new MailMessage();
mm.From = maFROM;
mm.To.Add(maTO);
mm.Subject = "html attachment";
mm.Priority = MailPriority.Normal;
mm.Body = "find attachment";
Attachment attach = new Attachment(AppDomain.CurrentDomain.BaseDirectory + "\\testKB.html");
mm.Attachments.Add(attach);
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
sc.UseDefaultCredentials = false;
sc.Credentials = new System.Net.NetworkCredential("email", "password");
sc.EnableSsl = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(mm);
}
catch (Exception ex)
{
lblMail.Text = ex.ToString();
// throw;
}
}
 
Execute the code and then check email with html attachment received in your inbox.