Feed on
Posts
Comments

Archive for the ‘.Net’ Category

GridViewRow pager = SearchResultsGridView.TopPagerRow;

if (pager != null)
{
[...]

Read Full Post »

Sometimes, there is a need to post a form from one page to another without any UI element. This is how to do it programmatically:
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(“FormElementName=” + formElementValue);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(http://somesite/somepage);
myRequest.Method = “POST”;
myRequest.ContentType = “application/x-www-form-urlencoded”;
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

Read Full Post »

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:ListBox ID=”LBSource” SelectionMode=”Multiple” runat=”server”>
  <asp:ListItem Text=”Item1″ Value=”vItem1″></asp:ListItem>
  <asp:ListItem Text=”Item2″ Value=”vItem2″></asp:ListItem>
  <asp:ListItem Text=”Item3″ Value=”vItem3″></asp:ListItem>
  <asp:ListItem Text=”Item4″ Value=”vItem4″></asp:ListItem>
  <asp:ListItem Text=”Item5″ Value=”vItem5″></asp:ListItem>
</asp:ListBox>
<input type=”button” value=”Add” onclick=”moveItems(’<%= LBSource.ClientID %>‘, ‘<%= LBDestination.ClientID %>‘)” />
<input type=”button” value=”Remove” onclick=”moveItems(’<%= LBDestination.ClientID %>‘, ‘<%= LBSource.ClientID %>‘)” />
<asp:ListBox [...]

Read Full Post »

    public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
    {
        // Check if the target directory exists, if not, create it.
        if (Directory.Exists(target.FullName) == false)
        {
            Directory.CreateDirectory(target.FullName);
        }
        // Copy each file into it’s new directory.
        foreach (FileInfo fi in source.GetFiles())
        {
            Console.WriteLine(@”Copying {0}\{1}”, target.FullName, fi.Name);
            fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
        }
        // Copy each subdirectory using recursion.
        [...]

Read Full Post »

Disable Compilation Error In C#

To disable a compilation error in C#, you only need to put this code just before the method declaration:
#pragma warning disable xxxx
Where xxxx is the error code from compilation like 0429 for example.

Read Full Post »

Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.
Read more…

Read Full Post »

C# Class & Methods Modifiers

Class Modifiers
The class is one of the two basic encapsulation constructs in C# (the other being the struct). Every executable statement must be placed inside a class or struct. Classes define reference types that are the basic building blocks of C# programs, and they are the architectural blueprint for the “objects” in OOP.
A class can [...]

Read Full Post »

Using Resources In .Net

Create .resx file and use this code:
string myValue = Resources.Messages.ResourceManager.GetString(myKey);
Where in resource file:
<data name=“myKey“ xml:space=“preserve“>
  <value>myValue</value>
</data>

Read Full Post »