Thursday, July 28, 2011

BlogEngine.NET open source projects for .NET, great learning source for developers

There are few open source projects available which help to learn more in creating blogs, portals,
intranet site and e - commerce also.
 
some of them are :
 

BlogEngine.NET

blogengine

URL: http://dotnetblogengine.net
Source Code: Grab the source code here
Project Description
BlogEngine.NET may be the simplest and most light weight ASP.NET blog at the moment,
but still full featured. Here are some of the features:

- Multi-author support
- Pingbacks and trackbacks
- Event based for plug-in writers
- Theming directly in master pages and user controls
- Gravatar and coComments implemented
- Live preview on commenting
- Comment moderation
- BlogML import/export
- Extension model
- Code syntax highlighting
- Mono support
- Full editing and creation of pages that are not posts
- Extended search capabilities
- Tag cloud
- Self updating blogroll
- Runs entirely on XML or SQL Server. Your choice.

YetAnotherForum

yetanotherjpg
YAF is a Open Source discussion forum or bulletin board system for web sites running
ASP.NET. The latest production version runs on ASP.NET v2.0 with a Microsoft SQL
Server backend.

URL: http://www.yetanotherforum.net/
Source Code: Grab the source code here

DotNetNuke

dotnetnuke
DotNetNuke is an open source web application framework ideal for creating, deploying and
managing interactive web, intranet, and extranet sites securely.

URL: http://www.dotnetnuke.com
Source Code: Grab the source code here

MojoPortal

mojoportal

URL: http://www.mojoportal.com/
Source Code: Grab the source code here

nopCommerce

nopcommerce

Running on C# nopCommerce is a fully customizable shopping cart. It's stable and highly
usable. nopCommerce is a open source e-commerce solution that is ASP.NET 3.5 based
with a MS SQL 2005 backend database.

URL: http://www.nopcommerce.com/
Source Code: Grab the source code here

 


 

Tuesday, July 26, 2011

progress Bar in swing

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class SplashScreen extends JWindow
{
private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;
private static Timer timer1;
public SplashScreen()
{

setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new javax.swing.border.EtchedBorder());
panel.setBackground(Color.red);
panel.setBounds(10,10,348,150);
panel.setLayout(null);

add(panel);
JLabel label = new JLabel("Hello World!");
label.setFont(new Font("Verdana",Font.BOLD,14));
label.setBounds(85,25,280,30);
panel.add(label);

progressBar.setMaximum(50);
progressBar.setBounds(55, 180, 250, 15);

add(progressBar);
loadProgressBar();
setSize(375,300);
setLocationRelativeTo(null);
setVisible(true);
}
public void loadProgressBar()
{
ActionListener al = new ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
count++;
progressBar.setValue(count);
if (count == 51){
timer1.stop();
execute.setVisible(false);

//load the rest of your application

}
}};
timer1 = new Timer(300, al);
timer1.start();
}

public static void main (String args[]){
execute = new SplashScreen();
}
}

Wednesday, July 20, 2011

Importance of Enumerations

Enumerations are simple value types that allow developers to choose from a list of constants.

Behind the scenes, an enumeration is just an ordinary integral number where every value has

a special meaning as a constant. However, because you refer to enumeration values using their

names, you don’t need to worry about forgetting a hard-coded number, or using an invalid

value.

To define an enumeration, you use the block structure shown here:

public enum FavoriteColors

{

Red,

Blue,

Yellow,

White

}

This example creates an enumeration named FavoriteColors with three possible values:

Red, Blue, and Yellow.

Once you’ve defined an enumeration, you can assign and manipulate enumeration values

like any other variable. When you assign a value to an enumeration, you use one of the predefined

named constants. Here’s how it works:

// You create an enumeration like an ordinary variable.

FavoriteColors buttonColor;

// You assign and inspect enumerations using a property-like syntax.

buttonColor = FavoriteColors.Red;

In some cases, you need to combine more than one value from an enumeration at once.

To allow this, you need to decorate your enumeration with the Flags attribute, as shown here:

[Flags]

public enum AccessRights

{

Read = 0x01,

Write = 0x02,

Shared = 0x04,

}

This allows code like this, which combines values using a bitwise or operator:

AccessRights rights = AccessRights.Read | AccessRights.Write | AccessRights.Shared;
You can test to see if a single value is present using bitwise arithmetic with the & operator

to filter out what you’re interested in:

if ((rights & AccessRights.Write) == AccessRights.Write)

{

// Write is one of the values.

}

Enumerations are particularly important in user-interface programming, which often has

specific constants and other information you need to use but shouldn’t hard-code. For example,

when you set the color, alignment, or border style of a button, you use a value from the appropriate

enumeration.

 

The Roles of Classes in Object-oriented programming

It’s important to remember that although all classes are created in more or less the same way

in your code, they can serve different logical roles. Here are the three most common examples:

Classes can model real-world entities. For example, many introductory books teach

object-oriented programming using a Customer object or an Invoice object. These

objects allow you to manipulate data, and they directly correspond to an actual thing in

the real world.

Classes can serve as useful programming abstractions. For example, you might use a

Rectangle class to store width and height information, a FileBuffer class to represent a

segment of binary information from a file, or a WinMessage class to hold information

about a Windows message. These classes don’t need to correspond to tangible objects;

they are just a useful way to shuffle around related bits of information and functionality

in your code. Arguably, this is the most common type of class.

Classes can collect related functions. Some classes are just a collection of static methods

that you can use without needing to create an object instance. These helper classes are the

equivalent of a library of related functions, and might have names like GraphicsManipulator

or FileManagement. In some cases, a helper class is just a sloppy way to organize code

and represents a problem that should really be broken down into related objects. In

other cases, it’s a useful way to create a repository of simple routines that can be used in

a variety of ways.

Understanding the different roles of classes is crucial to being able to master object-oriented

development. When you create a class, you should decide how it fits into your grand development

plan, and make sure that you aren’t giving it more than one type of role. The more vague a

class is, the more it resembles a traditional block of code from a non-object-oriented program.

 

check directory Exists in Ftp Server

 

public bool FtpDirectoryExists(string directoryPath, string ftpUser, string ftpPassword)

        {

            bool IsExists = true;

            try

            {

                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(directoryPath);

                request.Credentials = new NetworkCredential(ftpUser, ftpPassword);

                request.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;

 

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            }

            catch (WebException ex)

            {

                IsExists = false;

            }

            return IsExists;

        }

 

I have called this method as:
bool result = FtpActions.Default.FtpDirectoryExists( "ftp://domain.com/test",
                                                    txtUsername.Text, txtPassword.Text);

Sunday, July 17, 2011

check string exists in the enum and convert string to an Enum

/// <summary>

/// File Type Enum - The extensions that our application

/// support to work.. check at the time of work with the

/// file.. e.g. read the file and save to database etc.

/// </summary>

 

enum FileTypes

{

     BMP ,

     JPG ,

     JPEG,

     GIF,

    TIFF

}

 

string fileExtension = Path.GetExtension(filePath).ToUpper();

       

//check string exists in the enum.. it will match the case also..

if (Enum.IsDefined(typeof(FileTypes),fileExtension.Trim('.')))

{

    //convert string to enum

    FileTypes  c = (FileTypes) Enum.Parse(typeof(FileTypes), "MOV", true);

}

 

Note: Enum.IsDefined() doesn't offer the ignoreCase parameter. If you don't

know whether the casing is right, it seems the only way to do the conversion is using

the Parse method and catching the ArgumentException.

Saturday, July 9, 2011

Get textbox server control value using jquery in asp.net

Retrieve the server control id in the java script (jQuery code) and do as usual
jQuery code for getting the value at the ASPx page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
    <script type = "text/javascript">
        $(document).ready(function () {

            $("#<%= btnSend.ClientID %>").click(function () {
                alert($("#<%= txtInfo.ClientID %>").val());
                return true;
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style=" margin : 0px auto">
        <asp:TextBox ID="txtInfo" runat="server"></asp:TextBox>
        <
asp:Button ID="btnSend"  runat="server" Text="Send" />
    </div>
    </form>
</body>
</html>


Thursday, July 7, 2011

make a XtraGrid cell read-only on condition

using System;
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing;  
using System.Text; 
using System.Windows.Forms; 
using DevExpress.XtraGrid.Views.Grid; 
namespace ReturnForm
 {
      public partial class Form1 : Form {
          public ReturnForm()   
          {
              InitializeComponent();
          }
          private void Form1_Load(object sender, EventArgs e)
          {
              FillDataSource();
          } 
          private void FillDataSource()
          {
              dtProducts = dsProducts.dtProductsTableAdapter.Fill( 
                                                this.dsProducts.dtProducts);
          }
          private bool IsShipToUSCanada(GridView view, int row)
          {
              try
            {
                    string val = Convert.ToString(
                                view.GetRowCellValue(row, "ShipCountry"));
                  return (val == "US" || val == "Canada");
              }
             catch( )
            {
                  return false;
            }
      }
         private void grvProducts_ShowingEditor(object sender, CancelEventArgs e)
        {
              if(gridView1.FocusedColumn.FieldName == "IsFreeShipping" 
                 && IsShipToUSCanada(grvProducts, grvProducts.FocusedRowHandle))
                  e.Cancel = true;
       }
        private void grvProducts_RowCellStyle(object sender,
                      DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        { 
             if(e.Column.FieldName == "IsFreeShipping" 
                               && IsShipToUSCanada(grvProducts, e.RowHandle))
            {
                  e.Appearance.BackColor = Color.LightGray; 
             } 
         }
      }
  }

Tuesday, July 5, 2011

Extending jQuery functions, creating plugins

The jQuery wrapper function provides a large number of useful methods we’ll use
again and again in these pages. But no library can anticipate everyone’s needs. It
could be argued that no library should even try to anticipate every possible need;
doing so could result in a large, clunky mass of code that contains little-used features
that merely serve to gum up the works!

We could write our own functions to fill in any gaps, but once we’ve been spoiled
by the jQuery way of doing things, we’ll find that doing things the old-fashioned way is
beyond tedious. By extending jQuery, we can use the powerful features it provides,
particularly in the area of element selection.

Moreover, enterprising jQuery users have extended jQuery with sets of useful functions
that are known as plugins.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="scripts/jquery-1.6.1.min.js" type="text/javascript" >
    </script>
    <script src="scripts/jquery.validate.js" type = "text/javascript">
    </
script>
    <script src ="scripts/jquery.validate-vsdoc.js" type ="text/javascript">
    </
script>
    <script type = "text/javascript">
       <!— Extends jQuery with function named makeRed -->
        $.fn.makeRed = function () {
            return this.each(function () {
                $(this).css({ backgroundColor: 'red' });
            });
        };

        $(function () {
            $("<p>Insert Me Somewhere</p>").insertAfter("#followme");

            $(function () {
                $("#ram").makeRed();
            });
        });
    </script>
</head>
<body>
<p id="followme">follow me!</p>
<div id="ram">Make me Red</div>
</body>
</html>

The jQuery wrapper means and does

When CSS was introduced to web technologies in order to separate design from content,

a way was needed to refer to groups of page elements from external style sheets.

The method developed was through the use of selectors, which concisely represent

elements based upon their type, attributes, or position within the HTML document.

Those familiar with XML might be reminded of XPath as a means to select elements

within an XML document. CSS selectors represent an equally powerful concept,

but are tuned for use within HTML pages, are a bit more concise, and are generally

considered easier to understand.

For example, the selector

p a

refers to the group of all links (<a> elements) that are nested inside a <p> element.

jQuery makes use of the same selectors, supporting not only the common selectors

currently used in CSS, but also some that may not yet be fully implemented by all

browsers, including some of the more powerful selectors defined in CSS3.

To collect a group of elements, we pass the selector to the jQuery function using

the simple syntax

$(selector)

or

jQuery(selector)

Although you may find the $() notation strange at first, most jQuery users quickly

become fond of its brevity. For example, to wrap the group of links nested inside any

<p> element, we can use the following:

$("p a")

The $() function (an alias for the jQuery() function) returns a special JavaScript

object containing an array of the DOM elements, in the order in which they are defined

within the document, that match the selector. This object possesses a large number of

useful predefined methods that can act on the collected group of elements.

In programming parlance, this type of construct is termed a wrapper because it

wraps the collected elements with extended functionality. We’ll use the term jQuery

wrapper or wrapped set to refer to this set of matched elements that can be operated on

with the methods defined by jQuery.