How to show the ASP.NET code to the users
Use namespace System.IO System.Text VB.NET Protected Function GetCode(filename As String) As String Dim sr As New StreamReader(filename) Dim sb As New StringBuilder() sb.Append(‘<code><pre>’) sb.Append(sr.ReadToEnd()) sb.Append(‘</pre></code>’) sr.Close() Return sb.ToString() sb = Nothing sr = Nothing End Function ’GetCode Private Sub Button1_Click(sender As Object, e As System.EventArgs) Response.Write(GetCode((Server.MapPath(‘WebForm1.aspx’) + ‘.vb’))) End Sub ’Button1_Click C# protected string GetCode(string filename) { StreamReader sr =new StreamReader(filename ); StringBuilder sb =new StringBuilder(); sb.Append(‘<code><pre>’); sb.Append(sr.ReadToEnd()); sb.Append(‘</pre></code>’); sr.Close(); return sb.ToString(); sb = null; sr = null; } private void Button1_Click(object sender, System.EventArgs e) { Response.Write (GetCode(Server.MapPath (‘WebForm1.aspx’) + ‘.cs’)); }
How to select a specific Item in a ListBox in code
VB.NET ListBox1.Items.FindByValue(<Value>).Selected = true ’ListBox1.Items.FindByText(<Text>).Selected = true C# ListBox1.Items.FindByValue(<Value>).Selected = true; //ListBox1.Items.FindByText(<Text>).Selected = true;
How do I send an email with attachments
VB.NET Dim mailattach As New MailAttachment(Server.MapPath(‘<yourfilename>’)) mail.Attachments.Add(mailattach) C# MailAttachment mailattach = new MailAttachment( Server.MapPath( ‘<yourfilename>’ ) ); mail.Attachments.Add( mailattach );
How can I use a ‘friendly name’ in the To and From properties
Format the email address this way: VB.NET mail.From = ‘Name <[email protected]>’ mail.To = ‘Name <[email protected]>’ C# mail.From = ‘Name <[email protected]>’; mail.To = ‘Name <[email protected]>’;
How to align the text on a bitmap
VB.NET … Dim sFormat As New StringFormat() sFormat.Alignment = StringAlignment.Far … g.DrawString(‘Syncfusion’, New Font(‘Arial’, 16, FontStyle.Italic), SystemBrushes.WindowText, New PointF(2, 2), sFormat) …… C# … StringFormat sFormat = new StringFormat() ; sFormat.Alignment = StringAlignment.Far; … g.DrawString(‘Syncfusion’, new Font(‘Arial’, 16, FontStyle.Italic), SystemBrushes.WindowText, new PointF(2, 2), sFormat) ; ……