-->

Saturday, January 18, 2014

About the Folders in MVC Web Application in Visual Studio

In Visual Studio, when programmer creates a new MVC 4 Web Application some folders and files added by default. These folders contains Controllers, Models, and Views etc. to be complete MVC framework basis. The following figure shows the solution explorer created by default application:

MVC 4 Solution Explorer in Visual studio

App_Data

As the name implies, this folder will contains all the data related to our application. In further articles, we will use this folder to add a database (SQL database).

App_Start

All the files used to start the application are placed in this folder. These files contains AuthConfig, BundleConfig and RouteConfig etc. To specify routes for the application, add some files dynamically may be done by using these files.

Content

Content folder contains themes folder including css files, static files, icons and images used by the application. A default Site.css file is added in this folder that creates standard theme for the application. Programmer can change these themes as per the roles, account by using these folder.

Controllers

MVC gives all the controller the standard name suffix with “Controller”. The default mvc application have two controller i.e. AccountController and HomeController. These controller have some actions defined, used for redirection of the user. Programmer can add more controllers as per the requirements and any controller have multiple actions discussed later.

Models

Classes represents the application model for your application are defined in this folder. These classes may be used to create validation for the fields entered by the user. We will add some model classes in this folder in later article. It have default model added in the visual studio MVC application.

Views

Pages shown to the user, according to the controller classes are stored in this folder. Related views may be placed in a folder having the same name of controller by which these views relates. Any controller have some standard actions like Index, Create, Edit and Delete. The related views folder have all these views having the same name.
These views may have aspx or razor pages according to the requirement of the programmer.

Scripts

JavaScript files used by the application are stored in this folder. By default MVC add approx. 15 js files in the folder which are standard java script files. Programmer can also add some new files and use them in the application.

Thursday, January 16, 2014

How to search item from database using stored procedure in ASP.NET

Step-1: First create a Database Table in visual studio
I have some columns like

SNO    int      primarykey with auto increment by 1
Title      nvarchar(50)  Allow Null
MetaDescription  nvarchar(MAX)  Allow Null
URL   nvarchar(200) Allow Null

Step-2: Add TextBox, Button and GridView control into the .aspx page
Step-3: Create a static class for connection.
Step-4: Handle Button_click event

<p>
        Enter Text Here :
        <asp:TextBox ID="TextBox1" runat="server" Height="32px" Width="237px"></asp:TextBox>
    </p>
    <p>
        <asp:Button ID="Button1" runat="server" Height="33px" onclick="Button1_Click" 
            Text="Search" Width="122px" />
    </p>
    <p>
        <asp:GridView
         AutoGenerateColumns ="false"
          ID="GridView1" runat="server"
           Height="180px" Width="426px"
                        GridLines ="None" 
                                AllowPaging="True" 
            onpageindexchanging="GridView1_PageIndexChanging" PageSize="5" 
            ShowHeader="False">

           <Columns>
           <asp:TemplateField>
              <ItemTemplate>
                  <asp:HyperLink ID="HyperLink1" runat="server" Text ='<%# Eval("title") %>' NavigateUrl='<%# Eval("URL") %>'/>
                  <br />
                  <asp:Label ID="Label1" runat="server" Text='<%# Eval("title") %>'/><br />
               <asp:Label ID="description" runat="server" Text='<%# Eval("metaDescription") %>'/>
               <asp:Label ID="Label2" runat="server" Text='<%# Eval("keywords") %>'/>
              </ItemTemplate>
               
           </asp:TemplateField>
           
          
           </Columns>
        
        </asp:GridView>
    </p>
<p>
        &nbsp;</p>

.aspx.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    DataSet ds = new DataSet();
        
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        loadgrid();

    }

    private void loadgrid()
    {
        con.ConnectionString = connection.Connectionstring;
        con.Open();
        cmd.CommandText = "GetEngine";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@parameter", TextBox1.Text);
        cmd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        loadgrid();
    }
}

Connection Class  file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

/// <summary>
/// Summary description for connection
/// </summary>
public static class connection
{
    private static string DBConnectionString;
static connection()
{
        DBConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
}
    public static string Connectionstring
    {
        get
        {
            return DBConnectionString;
        }
    
    }
}

Stored Procedure code

Create Procedure GetEngine
@parameter nvarchar(100)
As
Select * from SearchEngine where Title like '%'+@parameter+'%' or MetaDescription like '%'+@parameter+'%' or  URL like '%'+@parameter+'%'


Code generate the following output

How to search item from database using stored procedure in ASP.NET

Wednesday, January 15, 2014

Search Engine project with source code in ASP.NET

Download this project

Project cost : 300Rs or $10
Pay me at:

Via bank transfer
 
ICICI bank account number is :    153801503056
Account holder name is :                 Tarun kumar saini
IFSC code is :                                   ICIC0001538

SBBJ bank detail :                             61134658849
Account holder name:                        Tarun kumar saini
IFSC code :                                        SBBJ0010398


CONTACT ME

Introduction

Search engine means , you can search any item from the database. Basically a search engine depends on various algorithms. In this project we use simple search algorithm. That algorithm is
First you fill the table by some value like insert title, description, URL, keywords etc. After feeding the data you can search in it.

Software requirement of the project are

1. Visual Studio 2010 with sql server 2008

Download

mail to me : narenkumar851@gmail.com     for project source code

Designing patterns 

1. First prepare master page for outer structure.
2. Search item using TextBox from database also take output in Gridview.
3. Design Admin Login page for feeding data into database table.
4. Also set permission for admin (admin can remove item from database table)


Search Code using stored procedure

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <p>
        Enter Text Here :
        <asp:TextBox ID="TextBox1" runat="server" Height="32px" Width="237px"></asp:TextBox>
    </p>
    <p>
        <asp:Button ID="Button1" runat="server" Height="33px" onclick="Button1_Click" 
            Text="Search" Width="122px" />
    </p>
    <p>
        <asp:GridView
         AutoGenerateColumns ="false"
          ID="GridView1" runat="server"
           Height="180px" Width="426px" GridLines ="None" AllowPaging="True" 
            onpageindexchanging="GridView1_PageIndexChanging" PageSize="5" 
            ShowHeader="False">
           <Columns>
           <asp:TemplateField>
              <ItemTemplate>
                  <asp:HyperLink ID="HyperLink1" runat="server" Text ='<%# Eval("title") %>' NavigateUrl='<%# Eval("URL") %>'/>
                  <br />
                  <asp:Label ID="Label1" runat="server" Text='<%# Eval("title") %>'/><br />
               <asp:Label ID="description" runat="server" Text='<%# Eval("metaDescription") %>'/>
               <asp:Label ID="Label2" runat="server" Text='<%# Eval("keywords") %>'/>
              </ItemTemplate>
               
           </asp:TemplateField>
           
          
           </Columns>
        
        </asp:GridView>
    </p>
<p>
        &nbsp;</p>
</asp:Content>


Csharp File code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    DataSet ds = new DataSet();
     
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        loadgrid();

    }

    private void loadgrid()
    {
        con.ConnectionString = connection.Connectionstring;
        con.Open();
        cmd.CommandText = "GetEngine";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@parameter", TextBox1.Text);
        cmd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        loadgrid();
    }
}


Search Engine project with source code  in ASP.NET

Search Engine project with source code  in ASP.NET


If you want to purchase this please contact me on :  narenkumar851@gmail.com

Tuesday, January 14, 2014

How to create and read Profile Group in ASP.NET

Step-1: Add this code into web.config file

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
      <authentication mode="Windows" />
      <profile>
        <properties>
          <group name ="AuthorInfo">
            <add name="AuthorName"/>
            <add name ="age"/>
            <add name="rights"/>
              
            
          </group>

          <group name ="EditorInfo">

            <add name ="EditorName"/>
            <add name ="EditorMail"/>
            <add name ="Editorrights"/>
          </group>
          
        </properties>
      </profile>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>

Step-2: Add this code into .aspx file
 
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {
        // Author Information
        Profile.AuthorInfo.AuthorName = "Rhett Butler";
        Profile.AuthorInfo.age = "30";
        Profile.AuthorInfo.rights = "Article writing";
        
        // Editor Information

        Profile.EditorInfo.EditorName = "Jacob Lefore";
        Profile.EditorInfo.EditorMail = "narenkumar851@gmail.com";
        Profile.EditorInfo.Editorrights = "full rights";
        
        
       
        
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text += "<b>Author Information</b><br/>";
        Label1.Text += Profile.AuthorInfo.AuthorName+"<br/>";
        Label1.Text += Profile.AuthorInfo.age + "<br/>";
        Label1.Text += Profile.AuthorInfo.rights + "<br/>";
        Label1.Text += "<b>Editor Information</b><br/>";
        Label1.Text += Profile.EditorInfo.EditorName + "<br/>";
        Label1.Text += Profile.EditorInfo.EditorMail  + "<br/>";
        Label1.Text += Profile.EditorInfo.Editorrights + "<br/>";
        
        
        
        
        
        
    }
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Get Lastupdated Date</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>Create user Group</h2>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get user Group" 
            Width="169px" onclick="Button1_Click" />
        <br /><br />  
    </div>  
    </form>  
</body>  
</html>

Code Generate the following output

How to create and read Profile Group in ASP.NET

How to Get Last Activity Date of Profile user in ASP.NET

Step-1: Add this code into web.config file

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
      <authentication mode="Windows" />
      <profile>
        <properties>
          <add name="UserName"/>
        </properties>
      </profile>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>

Step-2: Add this code into .aspx page (Before add this code, please create profile first )

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {
       
        
    }  

    protected void update_date(object sender, EventArgs e)
    {
        Label1.Text += "current Date and Time is " + DateTime.Now.ToString() +"<br/>";
        Label1.Text += "Profile LastUpdate Date is " + Profile.LastActivityDate; 
            
         

    }
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Get Last Activity Date</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>Get Last activity Date</h2>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get Last Activity Date" 
            Width="169px" onclick="update_date" />
        <br /><br />  
    </div>  
    </form>  
</body>  
</html>
Code Generate the following output
How to Get Last Activity Date of Profile user in ASP.NET

Monday, January 13, 2014

How to Get Last Updated Date of Profile user in ASP.NET

Step-1: Add this code into web.config file

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
      <authentication mode="Windows" />
      <profile>
        <properties>
          <add name="UserName"/>
        </properties>
      </profile>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>

Step-2: Add this code into .aspx page (Before add this code, please create profile first )

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {
       
        
    }  

    protected void update_date(object sender, EventArgs e)
    {
        Label1.Text += "current Date and Time is " + DateTime.Now.ToString() +"<br/>";
        Label1.Text += "Profile LastUpdate Date is " + Profile.LastUpdatedDate;
         

    }
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Get Lastupdated Date</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>Last updated Date</h2>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get Last Updated Date" 
            Width="169px" onclick="update_date" />
        <br /><br />  
    </div>  
    </form>  
</body>  
</html>

Code Generate the following output

How to Get Last Updated Date of Profile user in ASP.NET

ProfileManager.DeleteProfile method delete profile in asp.net example

Step-1: Add this code in web.config file
<configuration>

    <system.web>
      <authentication mode="Windows" />
      <profile>
        <properties>
          <add name="UserName"/>
        </properties>
      </profile>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>

Step-2: Add this code into your .aspx page

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {   
        if(!Page.IsPostBack)  
        {
            Profile.UserName = "Jacob Lefore";
            Profile.Save();
            Label1.Text = "Current User:" + Profile.UserName;  
        }  
    }  
  

    

    protected void DelteProfile(object sender, EventArgs e)
    {
        ProfileManager.DeleteProfile(User.Identity.Name);
        Profile.Save();
        Label1.Text = "Profile Deleted";

    }
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Delete Users Profile</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>Delete User Profile</h2>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Delete User Profile" 
            Width="169px" onclick="DelteProfile" />
        <br /><br />  
    </div>  
    </form>  
</body>  
</html>
Code generate the following output
ProfileManager.DeleteProfile method delete profile in asp.net example
ProfileManager.DeleteProfile method delete profile in asp.net example
ProfileManager.DeleteProfile method delete profile in asp.net example
ProfileManager.DeleteProfile method delete profile in asp.net example





© Copyright 2013 Computer Programming | All Right Reserved