Monday, 17 February 2014

Defination..

Class:-
A class Contains the member Variables(property) & member function (Function/methods).
Memory does not allocate untill object is not created.

A member function of a class is a function that has its definition or its prototype within the class definition like any other variable.
It operates on any object of the class of which it is a member, and has access to all the members of a class for that object.Member variables are attributes of an object and they are kept private to implement encapsulation. These variables can only be accessed using the public member functions.
We can say A class is the definition of an object.
Every instance of a class (except an abstract class) is an object?


abstract class:-
The purpose of abstract class is to provide default functionality to its sub classes.
When a method is declared as abstract in the base class then every derived class of that class must provide its own definition for that method.
An abstract class can also contain methods with complete implementation, besides abstract methods.
When a class contains at least one abstract method, then the class must be declared as abstract class.
It is mandatory to override abstract method in the derived class.
When a class is declared as abstract class,
then it is not possible to create an instance for that class. But it can be used as a parameter
in a method.

Access Modifier -:

An access modifier is a keyword of the language that is used to specify the access level of members of a class.
 Different Access Modifiers in C# are Public, Private, Protected, internal, protected internal.
 Default access modifier for members of class is private.
 Namespace will not have access modifier.
 Default access modifier for class ,struct, Interface, Enum, Delegate  is Internal.
 Default access modifier for class and struct members is private.
 No access modifier can be applied to interface members and always interface members are public.
 Enum members are always public and no access modifier can be applied.

There are  following access modifiers.
 Public: When Members of a class are declared as public, then they can be accessed
1.    Within the class in which they are declared.
2.    Within the derived classes of that class available within the same assembly.
3.    Outside the class within the same assembly.
4.    Within the derived classes of that class available outside the assembly.
5.    Outside the class outside the assembly.
Internal: When Members of a class are declared as internal, then they can be accessed
1.    Within the class in which they are declared.
2.    Within the derived classes of that class available within the same assembly.
3.    Outside the class within the same assembly.
Protected: When  Members  of  a  class  are  declared  as  protected,  then  they  can  be accessed
1.    Within the class in which they are declared.
2.    Within the derived classes of that class available within the same assembly.
3.    Within the derived classes of that class available outside the assembly.
Protected internal: When Members of a class are declared as protected internal, then they can be    accessed
1.    Within the class in which they are declared.
2.    Within the derived classes of that class available within the same assembly.
3.    Outside the class within the same assembly.
4.    Within the derived classes of that class available outside the assembly.
Private: Private members of a class are completely restricted and are accessible only within the class in which  they are declared.








Friday, 22 November 2013

Repeater/Gridview for Web Application

Repeator
 on page behind-----:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShowDetailsInRepeater.aspx.cs" Inherits="GarageDetails.ShowDetailsInRepeater" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <center>
    `<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
    <td>
    <asp:Label ID="lblRepFirstName" runat="server" Text="Enter The Name"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="txtRepFirstName" runat="server"
            ontextchanged="txtRepFirstName_TextChanged">
    </asp:TextBox>
    </td>
    </tr>
    <asp:Repeater id="GetGarageDetails" runat="server"
            >

<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>CustomerId</th>
<th>FirstName</th>
<th>LastName</th>
<th>ContactNumber</th>
<th>VehicleName</th>
<th>ChesisNumber</th>
<th>EngineNumber</th>
<th>RegistrationNumber</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblCustomerId" runat="server" Text='<%# Eval("CustomerId")  %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblLastName" runat="server" Text='<%#Eval("LastName") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblContactNumber" runat="server" Text='<%#Eval("ContactNumber") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblVehicleName" runat="server" Text='<%#Eval("VehicleName") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblEngineNumber" runat="server" Text='<%#Eval("EngineNumber") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblChesisNumber" runat="server" Text='<%#Eval("ChesisNumber") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblRegistrationNumber" runat="server" Text='<%#Eval("RegistrationNumber") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>
   
   
   
   
    </table>
    </center>
    </div>
    </form>
</body>
</html>
---------------------------------------
                                    OR
Grid 
Page Behing Code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="grid.aspx.cs" Inherits="VehicleManagementSystem.grid" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table  border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td>
    <asp:Label ID="lblName" runat="server" Text="Enter the name to be searched"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="txtName" runat="server" ontextchanged="txtName_TextChanged" AutoPostBack="true"></asp:TextBox>
    </td>
    </tr>

    </table>
   
    <asp:GridView ID="GridForData" runat="server" AutoGenerateColumns="false">

    <Columns>
    <asp:BoundField DataField="OwnerId" HeaderText="OwnerId"/>
 
    <asp:BoundField DataField="OwnerFirstName" HeaderText="FirstName"/>
    <asp:BoundField DataField="OwnerMiddleName" HeaderText="MiddleName"/>
    <asp:BoundField DataField="OwnerLastName" HeaderText="LastName" />
    <asp:BoundField DataField="VehicalName" HeaderText="VehicalName"/>
    <asp:BoundField DataField="VehicalNo" HeaderText="VehicalNo"/>
    <asp:BoundField DataField="ChechisNo" HeaderText="ChechisNo"/>
   
    </Columns>

    </asp:GridView>
    </div>
    </form>
</body>

</html>


-----------------------------------------

DAL Page :-


 public DataTable GetOwnerDetailsForGridview(string OwnerFirstName)
        {
            SqlConnection con = new SqlConnection(Setting.ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_GetOwnerDetailsForGridview";
            cmd.Parameters.AddWithValue("OwnerFirstName", OwnerFirstName);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);

            DataTable dt = ds.Tables[0];
            return dt;
        }

---------------------------------
ON Page:-

 protected void txtOwnersFirstName_TextChanged(object sender, EventArgs e)
        {
            string OwnerFirstName = txtOwnersFirstName.Text;
            VehicalDetailsDAL vehicalsDetailsDAL = new VehicalDetailsDAL();
            RepeaterForData.DataSource =            vehicalsDetailsDAL.GetOwnerDetailsForGridview(OwnerFirstName);
            RepeaterForData.DataBind();
        }

Store Procedure..............

Function:-

Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a value or may return more than one value using the OUT parameter.

Function can be called from SQL statements where as procedure can not be called from the sql statements

Functions are normally used for computations where as procedures are normally used for executing business logic.

You can have DML (insert,update, delete) statements in a function. But, you cannot call such a function in a SQL query.

Function returns 1 value only. Procedure can return multiple values (max 1024).

Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during creation but runtime throws error Function wont support deferred name resolution.


Stored procedure:-

Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values

Stored procedure is precompiled execution plan where as functions are not.

A procedure may modify an object where a function can only return a value The RETURN statement immediately completes the execution of a subprogram and returns control to the caller.




Create Table:-

Create Table OwnerDetails (OwnerId int Identity(1,1) Primary Key, OwnerFirstName nvarchar(255), OwnerMiddleName nvarchar(255), OwnerLastName nvarchar(255));

Create Table VehicalDetails (VehicalId int identity(1,1) Primary Key, OwnerId int Foreign Key References OwnerDetails(OwnerId))

Alter Table VehicalDetails Add VehicalName nvarchar(255), ChechisNo int, VehicalNo nvarchar(255)

---------------
Writting Procedure:-

 To Insert
Create Proc usp_AddOwnerDetails
@OwnerFirstName nvarchar(255),
@OwnerMiddleName nvarchar(255),
@OwnerLastName nvarchar(255)
as begin
insert into OwnerDetails(OwnerFirstName,OwnerMiddleName,OwnerLastName)Values(@OwnerFirstName,@OwnerMiddleName,@OwnerLastName)
Select Scope_Identity( )
end
-----------------------------

 To Update

Create Proc usp_UpdateOwnerDetails
@OwnerFirstName nvarchar(255),
@OwnerMiddleName nvarchar(255),
@OwnerLastName nvarchar(255),
@OwnerId int
as begin
Update OwnerDetails set OwnerFirstName=@OwnerFirstName,OwnerMiddleName=@OwnerMiddleName,OwnerLastName=@OwnerLastName where OwnerId=@OwnerId
end

-----------------------------------
 ToDelete

Create Proc usp_DeleteOwnerDetails
@OwnerId int
as begin
Delete From OwnerDetails where OwnerId=@OwnerId
end

------------------------------------------
 To Search

Create Proc usp_SearchOwnerDetails
@OwnerId int
as begin
Select* From OwnerDetails where OwnerId=@OwnerId
end


----------------------------------
 To GridView:-
SP for GridView By FirstName:-

Create proc usp_GetOwnerDetailsForGridview
@OwnerFirstName nvarchar(255)
as
begin
Select o.OwnerId,o.OwnerFirstName,o.OwnerMiddleName,o.OwnerLastName,v.VehicalName,v.VehicalNo,v.ChechisNo from OwnerDetails o inner join VehicalDetails v on v.OwnerId=o.OwnerId where o.OwnerFirstName like '%'+@OwnerFirstName+'%'
end

----------------------

Thursday, 14 November 2013

Code For DAL, BAL & Code At ASPX Page..

   Code to Create Connection String Page:

-------------------------------------

DAL Code:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace VehicleManagement
{
    public class VehicalDetailsDAL
    {
        public int VehicalDetailsId { get; set; }
        public int OwnerId { get; set; }
        public string VehicalName { get; set; }
        public string ChechisNo { get; set; }
        public string VehicalNo { get; set; }

        SqlConnection conn = new SqlConnection(Setting.ConnectionString);
---------------------------------------------------------------------------------------------------
To Insert:-


        public int AddVehical(VehicalDetailsDAL vehicalDetailsDAL)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_VehicalDetails";
            cmd.Parameters.AddWithValue("@VehicalDetailsId", vehicalDetailsDAL.VehicalDetailsId);
            cmd.Parameters.AddWithValue("@OwnerDetailsId", vehicalDetailsDAL.OwnerId);
            cmd.Parameters.AddWithValue("@VehicalName", vehicalDetailsDAL.VehicalName);
            cmd.Parameters.AddWithValue("@ChechisNo", vehicalDetailsDAL.ChechisNo);
            cmd.Parameters.AddWithValue("@VehicalNo", vehicalDetailsDAL.VehicalNo);

            int VehicalDetailsId = Convert.ToInt16(cmd.ExecuteScalar());
            conn.Close();
            return VehicalDetailsId;

        }
---------------------------------------------------------------------------------------------------
To Delete:-

        public void DeleteVehical(int VehicalDetailsId)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_DeleteVehicalDetails";
            cmd.Parameters.AddWithValue("@VehicalDetailsId", VehicalDetailsId);
            cmd.ExecuteNonQuery();
            conn.Close();

        }
---------------------------------------------------------------------------------------------------
To Search:-

        public VehicalDetailsDAL SearchOwnerDetails(int VehicalDetailsId)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_SearchVehicalDetails";
            SqlDataReader dr = cmd.ExecuteReader();
            VehicalDetailsDAL v = new VehicalDetailsDAL();
            while (dr.Read())
            {
                v.VehicalDetailsId = Convert.ToInt16(dr["VehicalDetailsId"]);
                v.OwnerId = Convert.ToInt16(dr["OwnerDetailsId"]);
                v.VehicalName = dr["VehicalName"].ToString();
                v.ChechisNo = dr["ChechisNo"].ToString();
                v.VehicalNo = dr["VehicalNo"].ToString();
            }
            conn.Close();
            return v;

        }
---------------------------------------------------------------------------------------------------
To Update:-

        public void UpdateVehicalDetails(VehicalDetailsDAL vehicalDetailsDAL)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "usp_UpdateVehicalDetails";
            cmd.Parameters.AddWithValue("@VehicalDetailsId", vehicalDetailsDAL.VehicalDetailsId);
            cmd.Parameters.AddWithValue("@OwnerDetailsId", vehicalDetailsDAL.OwnerId);
            cmd.Parameters.AddWithValue("@VehicalName", vehicalDetailsDAL.VehicalName);
            cmd.Parameters.AddWithValue("@ChechisNo", vehicalDetailsDAL.ChechisNo);
            cmd.Parameters.AddWithValue("@VehicalNo", vehicalDetailsDAL.VehicalNo);
            cmd.ExecuteNonQuery();
            conn.Close();

       }
---------------------------------------------------------------------------------------------------

        }

}




     

------------------------------ BAL------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VehicleManagement;

namespace VehicalManagementBAL
{
    public class OwnerDetailsBAL
    {
        public string AddOwnerBAL(OwnerDetailsDAL ownerDetailsDAL)
        {
            if (string.IsNullOrEmpty(ownerDetailsDAL.OwnerFirstName))
            {
                throw new Exception("OwnerFirstName can not be Empty");

            }

            if (string.IsNullOrEmpty(ownerDetailsDAL.OwnerMiddleName))
            {
                throw new Exception("ownerMiddleName can not be empty");
            }

            if (string.IsNullOrEmpty(ownerDetailsDAL.OwnerLastName))

            {
                throw new Exception("ownerLastName can not be Empty");
            }
                 return ownerDetailsDAL.AddOwner(ownerDetailsDAL).ToString ();
        }


 

-----------------------------------------------------
 public DataSet SerachUserRecord(string txtFirstName)
     
 {
         
 SqlConnection con = new SqlConnection(Setting.ConnectionString);

 string query = "Select u.FirstName,p.ContactNumber,e.UserEmailId from UserInformation u inner join PhoneNumber p on u.UserId=p.UserId inner join EmailId e on p.UserId=e.UserId where u.FirstName='txtSearch.Text%'";
         
con.Open();
         
SqlCommand cmd = new SqlCommand(query, con);
         
cmd.Parameters.AddWithValue("@txtFirstName", txtFirstName);
         
       
  DataSet ds = new DataSet();
         
SqlDataAdapter da = new SqlDataAdapter(cmd);

         
 da.Fill(ds);
         
         
 if (ds.Tables[0].Rows.Count > 0)
            {
             
UserInformationDal userinfo = new UserInformationDal();
             
 userinfo.FirstName = ds.Tables[0].Rows[0]["FirstName"].ToString();
             
 userinfo.ContactNumber = ds.Tables[0].Rows[0]["ContactNumber"].ToString();
             
 userinfo.UserEmailId = ds.Tables[0].Rows[0]["UserEmailId"].ToString();
             
         
 }

         
con.Close();
         
 return ds;





---------------------------------------

Aspx-



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VehicleManagement;
using VehicalManagementBAL;

namespace VehicleManagementSystem
{
    public partial class VehicleInformation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSaveDetails_Click(object sender, EventArgs e)
        {
            VehicalDetailsDAL vehicalDetailsDAL = new VehicalDetailsDAL();

            vehicalDetailsDAL.VehicalName = txtVehicleName.Text;
            vehicalDetailsDAL.VehicalNo = txtVehicleNo.Text;
            vehicalDetailsDAL.ChechisNo = txtChechsisNo.Text;
            lblMessage.Text = "Added successfully ";
         

         
        }
    }
}
--------------------------------------



Code for Test Case.....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AddressBookBal;  
using AddressBookDal;
using NUnit.Framework;

namespace TestAddressBook
{
    [TestFixture]
    class TestUserInformation
    {
        [TestCase]
        public void TestAddNewUser()
        {  
            UserInformationBal userbal=new UserInformationBal();
            UserInformationDal userInformationDal=new UserInformationDal();
            userInformationDal.Title = "Mr";
            userInformationDal.FirstName="Ajay";
            userInformationDal.MiddleName = "ramesh";
            userInformationDal.LastName = "Sonkul";
            userInformationDal.Age = 30;
            userInformationDal.DateOfBirth = DateTime.Now;
            userInformationDal.Sex = "Male";
            userInformationDal.Category = "Family";

            String UserId = userbal.AddUserInformation(userInformationDal);
               
                UserInformationDal user = userbal.GetUserInfoById(UserId);
                if (user.Title == userInformationDal.Title && user.FirstName == userInformationDal.FirstName && user.MiddleName == userInformationDal.MiddleName && user.LastName == userInformationDal.LastName && user.Age == userInformationDal.Age && user.DateOfBirth == userInformationDal.DateOfBirth && user.Sex == userInformationDal.Sex && user.Category == userInformationDal.Category)
            {
                Assert.IsTrue(true);
            }
            else
            {
             //   userbal.GetUserInfoById(UserId);
                Assert.IsTrue(false);
           
            }

    }
        [TestCase]
        public void TestDeleteUser()
        {
            UserInformationBal userinfobal=new UserInformationBal();
            UserInformationDal userinfodal=new UserInformationDal();
            userinfodal.UserId = 24;
            userinfobal.DeleteUserInformation(userinfodal.UserId);
            UserInformationDal user= userinfobal.GetUserInfoById(userinfodal.UserId.ToString());
            if(userinfodal.UserId==user.UserId)
            {
                Assert.IsTrue(false);
            }  
            else
            {
                Assert.IsTrue(true);
            }
        }
        [TestCase]
        public void TestUpdateUser()
        {
            UserInformationDal userdal=new UserInformationDal();
            UserInformationBal userbal=new UserInformationBal();
           
            userdal.Title = "Ms";
            userdal.FirstName = "Pooja";
            userdal.MiddleName = "Sumit";
            userdal.LastName = "Mishra";
            userdal.Age = 22;
            userdal.DateOfBirth = DateTime.Now;
            userdal.Sex = "FeMale";
            userdal.Category = "Family";
            userdal.UserId = 42;

            userbal.UpdateInfo(42);
        }
    }
}

Query For Report, & Query for Insert, Update & SQL Store Procedure

Query For  Report:

SELECT        Patient_Visit.Patient_Id, Patient_Visit.Surname, Patient_Visit.Firstname, Patient_Visit.Middlename, Patient_Visit.Sex, Patient_Visit.Contact_no,
                         Patient_Details.Date_of_visit, Patient_Details.Date_of_discharge, Patient_Details.Symptoms, Patient_Details.Disease, Patient_Details.Treatment,
                         Patient_Details.DoctorName, Patient_Details.Age, Patient_Details.Occupation, Patient_Details.Sensitivity, Patient_Details.MentalStatus,
                         Patient_Details.sleep, Patient_Details.Nutrition, Patient_Details.Vitality, Patient_Details.PhysicalStatus, Patient_Details.Nature,
                         Patient_Details.Proving, Patient_Details.RemedySource, Patient_Details.Remedytype

FROM            (Patient_Details LEFT OUTER JOIN
                         Patient_Visit ON Patient_Details.Patient_Id = Patient_Visit.Patient_Id)
WHERE        (Patient_Details.Patient_Id = @ Patient_Id)

--------------------------------------------------------------------
Query for Indesert & Update

Insert---------->

string query = " insert into UserInformation(Title,FirstName,MiddleName,LastName,Age,DateOfBirth,Status,Category,Sex)values(" + Title + "," + FirstName + "," + MiddleName + "," + LastName + "," + Age + "," + DateOfBirth + "," + Status + "," + Category + ","+Sex+")";



Update----------->

 String query = "Update from UserInformation set Title,FirstName,MiddleName,LastName,Age,Category,status,DateOfBirth,Sex='" + Title + "','" + FirstName + "','" + MiddleName + "','" + LastName + "','" + Age + "','" + Category + "','" + Status + "','" + DateOfBirth + "','" + Sex + "'  where UserId='" + UserId + "'";

-------------------------------------

______________________________________________
Code At DAL using Store Procedure:
   
public string AddNewUsersInform()
     
{
         
SqlConnection conn = new SqlConnection(Settings.ConnectionString);

 SqlCommand cmd = new SqlCommand();
         
 cmd.Connection = conn;
         
cmd.CommandText = "uspAddNewUserInformation";
         
 cmd.CommandType = CommandType.StoredProcedure;
         
 cmd.Parameters.AddWithValue("@FirstName", FirstName);
         
 cmd.Parameters.AddWithValue("@MiddleName", MiddleName);
         
 cmd.Parameters.AddWithValue("@LastName", LastName);
         
cmd.Parameters.AddWithValue("@Age", Age);
         
cmd.Parameters.AddWithValue("@DateOfBirth", DateOfBirth);
         
cmd.Parameters.AddWithValue("@Sex", Sex);
       
  cmd.Parameters.AddWithValue("@Category", Category);

         
 string result = cmd.ExecuteScalar().ToString();
       
  return result;
     

 }




Monday, 11 November 2013

CODE TO CONVERT 'NOTEPAD TEXT' FILE IN HTML 'FILE' (WINDOW APPLICATION)

NOTE:- COPY  TEXT FILE'S  FOLDER  IN C DRIVE & NAMED IT AS 'DietNutrition'.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace TextToHtm
{
    class Program
    {
        static void Main(string[] args)
        {
            DirSearch(@"C:\DietNutrition");
        }
        public static void DirSearch(string sDir)
        {
            try
            {
                List<string> ttt = new List<string>();
                ttt.Add("<html><head><title>Index</title></head><body><br/>");
                foreach (string f in Directory.GetFiles(sDir))
                {
                    SearchFileAndAddToObject(f);
                    ttt.Add("<a href=" + f.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ", "") + ">" + f.Replace(".txt", "").Replace("DietNutrition", "DietNutritionHtm").Replace(@"C:\DietNutritionHtm\","")+"</a><br/>");
                 
                }
                ttt.Add("</body></html>");
                string f1 = @"C:\DietNutritionHtm\Index.html";
           //    File.Create(f1.Replace(" ", ""));
             File.WriteAllLines(f1.Replace(" ", ""), ttt.ToArray(), Encoding.GetEncoding("Windows-1252"));
                foreach (string d in Directory.GetDirectories(sDir))
                {

                    foreach (string f in Directory.GetFiles(d))
                    {
                        SearchFileAndAddToObject(f);
                    }

                    DirSearch(d);
                }
            }
            catch (System.Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            Console.ReadLine();
        }
        public static void SearchFileAndAddToObject(string filename)
        {


            string[] fileByLines = File.ReadAllLines(filename, Encoding.GetEncoding("Windows-1252"));
            List<string> tt = new List<string>();

            tt.Add("<html><head><title>");
            foreach (string line in fileByLines)
            {

                string Newline;
                if(line.Contains("["))
                {
                    Newline = "<title>" + line.Substring(0, line.IndexOf("[")).Replace("Œ", "") + @"</title></head><body style=""background-image:url(qhc_body.jpg)""><table width=""100%"" cellspacing=""0"" cellpadding=""0"" border=""0""><tr><td align=""center""><img src=""logo1.png"" alt=""Logo""  /></td></tr><tr><td>";
                 
                }
                else
                    Newline = line.Replace("Œ", "<b><u style=\"Color:660066\"><hr>") + "<b> </u><br/>";
             
               tt.Add(Newline);
               Newline = Newline.Replace("•", "*").Replace("-", "*");
             
            }
            tt.Add("</td></tr></table></body></html>");
            Directory.CreateDirectory(@"C:\DietNutritionHtm");
          // File.Create(filename.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ", ""));
       
           File.WriteAllLines(filename.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ",""), tt.ToArray(), Encoding.GetEncoding("Windows-1252"));

        }
    }
}