Archive for the ‘C#’ Category

Get server information from the url of website

Below dotnet code will get you some server information about a website it is hosted. Note that sever can mock or disable data it is provided.

WebClient wc = new WebClient();
string site = @"http://www.msdn.microsoft.com/";
[...]

Leave a Comment

C# Get Copyright information from current application using Reflection

Here is the code snippet:

private string GetCopyright()
{
Assembly asm = Assembly.GetExecutingAssembly();
object[] obj = asm.GetCustomAttributes(false);
foreach (object o in obj)
{
if (o.GetType() ==
typeof(System.Reflection.AssemblyCopyrightAttribute))
{
[...]

Leave a Comment

Show jquery imprompu popup from ASP.NET-AJAX

Simple

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "message",
"$.prompt(’Are you sure?’)", true);

VN:F [1.1.6_502]Rating: 0.0/5 (0 votes cast)

Leave a Comment

WinForms – Print using printDialog and printDocument

Code snippet here:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
DataSet ds = new DataSet();
public Form1()
{
[...]

Leave a Comment

Filter Listbox based on Textbox entry

Here is the C# code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
DataSet ds = new DataSet();
public Form1()
[...]

Leave a Comment

Two additional operators introduced in C# 4.0

“goes to” OR –> operator and
‘”is approached by” OR <–

Eg:

int x = 10;
// this is read "while x goes to zero"
while (x –> 0)
{
Console.WriteLine(x);
}

Output:
987…

int x = 10;
// this is read "while zero is approached by x"
while (0 <– x)
{
Console.WriteLine(x);
}

Output:
0123…

The same feature we [...]

Leave a Comment

How to print a WPF form

PrintDialog pd = new PrintDialog();
pd.ShowDialog();
pd.PrintVisual(this, "wpf printing");

VN:F [1.1.6_502]Rating: 0.0/5 (0 votes cast)

Leave a Comment

Load user controls dynamically with ASP.NET

ctrl_homegadget ctrl
= (ctrl_homegadget) LoadControl("ctrl_homegadget.ascx");
ctrl.Border = false;
ctrl.Title = "Hello";
pnlGedgets.Controls.Add(ctrl);

VN:F [1.1.6_502]Rating: 5.0/5 (1 vote cast)

Leave a Comment

Strip SQL Comments using RegularExpression with C#

Here is the code:

Regex r
= new Regex(@"(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(–.*)");
textBox2.Text
= r.Replace(textBox1.Text, string.Empty);

VN:F [1.1.6_502]Rating: 0.0/5 (0 votes cast)

Leave a Comment

C# typeof equivalent in Visual Basic

Visual Basic.NET equivalent of C#’s typeof is GetType and NOT TypeOf

VN:F [1.1.6_502]Rating: 5.0/5 (1 vote cast)

Leave a Comment