asp.net 2

How to get site visitor Api in asp.net

by Ali Raza Zaidi on February 25, 2012

How to get IP Host Address of remote Client

// To get IP of the client meachine
// There is two methods to obtain IP address

// Method 1
//     Gets the IP host address of the remote client.
// Returns:
//     The IP address of the remote client.
string ipMethod1 = Request.UserHostAddress; // HttpContext.Current.Request.UserHostAddress;

//Methord 2
//Request.ServerVariables is a Name Value Collection
//     Gets a collection of Web server variables.
// Returns:
//     A System.Collections.Specialized.NameValueCollection of server variables.
string ipMethod2 = Request.ServerVariables["REMOTE_ADDR"]; //HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
Response.Write(ipAdddress);

{ Comments on this entry are closed }

Simple Data Access Class for Access database

by Ali Raza Zaidi on February 19, 2012

After little time i have to wrote a simple data access layer for MS Access database,

For Connection string I wrote a simple Util Class as

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

/// <summary>
/// Summary description for Util
/// </summary>
public static  class Util
{

    public static string GetConnString()
    {
        return WebConfigurationManager.ConnectionStrings["myConnStr"].ConnectionString;
    }
}

 

Then i Wrote another class where Insert , update ,delete and simple select method placed as

Insert method

 public void InsertReviews(string _Nick, string _Name, string _EmailAddress, string _RealStateTitle, string _Address, string _City, string _ZipCode, string _Country, string _Comments, string _FromIP, string _Status, string _Langi, string _Lit)
    {
        string ConnString = Util.GetConnString();
        string SqlString = "Insert Into ClientInfo (Nick,Name,EmailAddress,RealStateTitle,Address,City,ZipCode,Country,Comments,FromIP,Status,Langi,Lit) Values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
        using (OleDbConnection conn = new OleDbConnection(ConnString))
        {
            using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("Nick", _Nick);
                cmd.Parameters.AddWithValue("Name", _Name);
                cmd.Parameters.AddWithValue("EmailAddress", _EmailAddress);
                cmd.Parameters.AddWithValue("RealStateTitle", _RealStateTitle);
                cmd.Parameters.AddWithValue("Address", _Address);
                cmd.Parameters.AddWithValue("City", _City);
                cmd.Parameters.AddWithValue("ZipCode", _ZipCode);
                cmd.Parameters.AddWithValue("Country", _Country);
                cmd.Parameters.AddWithValue("Comments", _Comments);
                cmd.Parameters.AddWithValue("FromIP", _FromIP);
                cmd.Parameters.AddWithValue("Status", _Status);
                cmd.Parameters.AddWithValue("Langi", _Langi);
                cmd.Parameters.AddWithValue("Lit", _Lit);
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }

    }

Update Method

  public void UpdateReviews(int _ID,string _Nick, string _Name, string _EmailAddress, string _RealStateTitle, string _Address, string _City, string _ZipCode, string _Country, string _Comments, string _FromIP, string _Status, string _Langi, string _Lit)
    {
        string ConnString = Util.GetConnString();
        string SqlString = "Update ClientInfo Set Nick=?,Name=?,EmailAddress=?,RealStateTitle=?,Address=?,City=?,ZipCode=?,Country=?,Comments=?,FromIP=?,Status=?,Langi=?,Lit=? where IDs=?";
        using (OleDbConnection conn = new OleDbConnection(ConnString))
        {
            using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("Nick", _Nick);
                cmd.Parameters.AddWithValue("Name", _Name);
                cmd.Parameters.AddWithValue("EmailAddress", _EmailAddress);
                cmd.Parameters.AddWithValue("RealStateTitle", _RealStateTitle);
                cmd.Parameters.AddWithValue("Address", _Address);
                cmd.Parameters.AddWithValue("City", _City);
                cmd.Parameters.AddWithValue("ZipCode", _ZipCode);
                cmd.Parameters.AddWithValue("Country", _Country);
                cmd.Parameters.AddWithValue("Comments", _Comments);
                cmd.Parameters.AddWithValue("FromIP", _FromIP);
                cmd.Parameters.AddWithValue("Status", _Status);
                cmd.Parameters.AddWithValue("Langi", _Langi);
                cmd.Parameters.AddWithValue("Lit", _Lit);
                cmd.Parameters.AddWithValue("IDs", _ID);
               conn.Open();
                cmd.ExecuteNonQuery();
            }
        }
    }

Delete Method

 public void DelteReviews(int _ID)
    {
        string ConnString = Util.GetConnString();
        string SqlString = "Delete * From ClientInfo where IDs=?";
        using (OleDbConnection conn = new OleDbConnection(ConnString))
        {
            using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("IDs", _ID);
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }

    }

Select Method as

 public DataSet SelectReviews(int _ID)
    {
        string ConnString = Util.GetConnString();
        string SqlString = "Select * From ClientInfo where IDs=?";
        DataSet _ds = new DataSet();
        using (OleDbConnection conn = new OleDbConnection(ConnString))
        {
            using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("IDs", _ID);
                OleDbDataAdapter _Adp = new OleDbDataAdapter();
                _Adp.SelectCommand = cmd;
                _Adp.Fill(_ds);
                _Adp.Dispose();
                conn.Open();
            }

        }
        return _ds;
    }

Chears :)

{ Comments on this entry are closed }

Best advice for your preparation for 70-536

by Ali Raza Zaidi on September 4, 2009

As is known to everyone, if you learn and master each and every aspect of the subject and get a hand on experience on it, and then you will not have any problems, that is to say, you absolutely will get 70-536!!But, we could not become a master in .net framework-application Development Foundation in singe half year or one year.

When you read it here, maybe you’ll be confused and ask how the candidate for MCTS 70-536 could make it in a couple of months?? Of course, we can make it if you follow the steps as this article said below:

To pass the exams, the 70-536 candidates should firstly focus on important areas. So, you should pay attention to the official site since the guideline is subject to change at any time without prior notice and at the sole discretion of Microsoft. Generally speaking, there won’t be substantial change.

Here is the guide for 70-536:

1. Developing applications that use system types and collections (15 percent)

2. Implementing service processes, threading, and application domains in a .NET Framework application (11 percent)

3. Embedding configuration, diagnostic, management, and installation features into a .NET Framework application (14 percent)

4. Implementing serialization and input/output functionality in a .NET Framework application (18 percent)

5. Improving the security of .NET Framework applications by using the .NET Framework security features (20 percent)

6. Implementing interoperability, reflection, and mailing functionality in a .NET Framework application (11 percent)

7. Implementing globalization, drawing, and text manipulation functionality in a .NET Framework application (11 percent)

Of course, the detail information won’t be listed; however, it could help us decide how much time we should spend in each major topic area according to the relative weight on the exam.

So, we have known what object we’ll achieve, and then we should have the best materials for us to prepare 70-536.

1. Good online training websites. They can provider many resources for us to better know the objectives and better prepare the exams. All Microsoft exams have a set of objectives outlining the topics you need to understand to become successful in the exam. It is a good practice to visit the Microsoft’s site to check the latest exam details, because these objectives keep on changing from time to time.

2. Outstanding software that really trains for this exam.

3. Good books .Here is the two books. Step by step book which I would recommend you to start with:

1. The Microsoft Certified Application Specialist Study Guide

2. MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0 Foundation

So, after all preparations are done, we need to make a plan to prepare the exam!!! The following plan is just for your reference, and you should find the best suit for yourself.

1. Fix your daily hours of study and set a deadline for completing the entire contents. This will help you prepare efficiently for the exam.

2. Once you have created your study plan, you should attempt the diagnostic tests, and you should concentrate your studies on these objectives, as a thorough knowledge of the topics included in them is essential for passing the exam.

3. Study Notes: The Study notes are organized according to the actual test objectives. It helps you understand the topics clearly and systematically, assist you in difficult areas and organize your studies. They provide in-depth knowledge of different topics and help you become a master in the respective field.

4. Practice questions are necessary to get an overview on the type of questions you will encounter in the actual exams. The more you practice, the better understanding you will have on the type of questions you will face. Microsoft has included different types of questions like ‘hot area’, ‘build list and reorder’, ‘drag and drop’, and the latest ’simulation questions’ in its exams.

5. Quiz: The exam quiz helps you learn the technical terms, concepts and definitions, etc., that are essential for the real exams. You can set your own time for the quiz, and can even set the time allowed for each question to appear. Customized pop quizzes can also be created by selecting the topics and number of questions from each topic, so that you can prepare for the real exam quickly and effectively.

6. Track your progress: You should keep track of your progress over time by going through the detailed test report provided at the end of each practice test.

7. Register for the test: Nothing beats than setting a deadline. Therefore, you should register for the test at least two weeks in advance. This helps in building the tempo and keeps you more focused and determined.

8. Quickly review just before taking the test: As your exam day nears, it is a good time to go through a quick review on all the tips, notes, exam alerts and summary given at the end of each chapter. Glance through the topic briefly if you have doubts. Be relaxed and have a good amount of sleep.

P.S.

Maybe many candidates have those questions like would some types of questions on MS be on the exams??

I think if it’s covered in your study materials (i.e. MS Press book), then it’s probably on the exam.  Note that MS doesn’t release the number or exact types of questions on the exams.  If you use a MS Press book, then it comes with the MeasureUp practice exams.  Those are the types of questions you’ll see on the actual exam. No matter what types of questions in your paper, you will succeed in 70-536 as long as you know all subjects fully! How much of the knowledge you grasp is the key in your exams.

Finally ,wish you  successful in your exams !!!

{ Comments on this entry are closed }

whats new in asp.net 4.0

by Ali Raza Zaidi on June 26, 2009

read the following link

http://www.asp.net/learn/whitepapers/aspnet40/

{ Comments on this entry are closed }

How to get month date view between two dates in c#

by Ali Raza Zaidi on March 24, 2009

Scenario I got while developing some application. I required month and year view in drop down list between contract starting and ending date. Like “March 2009” “April 2009” until march 2011 so on.

I handled it as follow

DateTime _LoopDate = “1/1/2009”;
string month = string.Empty;
DateTime _EndDate = “1/1/2011”;

while (_LoopDate <= _EndDate)
{
System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
month = d.MonthNames[_LoopDate.Month - 1];

drpDate.Items.Add(new ListItem(month + ” ” + _LoopDate.Year.ToString(), _LoopDate.Month.ToString() + ” ” + _LoopDate.Year.ToString()));
//drpdate is dropdownlist
_LoopDate= _LoopDate.AddMonths(1);
}

{ Comments on this entry are closed }

very helpful link i found on internet http://csharpdotnetfreak.blogspot.com/2008/12/export-gridview-to-pdf-using-itextsharp.html

{ Comments on this entry are closed }

how to send mail smtp with authentication with web.mail class

by Ali Raza Zaidi on November 19, 2008

hi i used following code

MailMessage message = new MailMessage();

message.To = "myemailaccount@yahoo.com";

message.From = "myemailaccount@thecrystalrosary.com";
message.Subject = "Testing Internet SmtpMail";
message.BodyFormat = MailFormat.Html;

message.Body = "body";

message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.thecrystalrosary.com");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2); //2 to send using SMTP over the network
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); //1 = basic authentication
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");

try
{
SmtpMail.Send(message);
}
catch (Exception e)
{
// trap here
}

{ Comments on this entry are closed }

how to get oracle sequence numbers in .net

by Ali Raza Zaidi on October 24, 2008

hi the main Query to get sequence number is follow


select JOB_ID_SEQ.NEXTVAL from dual;

i get the required Sequence number value form following method

public int GetOracleSequenceValue(string _SequenceValue)
{
OdbcCommand _command = new OdbcCommand();
int _ItemValue = -1;
OdbcConnection _con = new OdbcConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["RCConnectionString"].ToString());
try
{
_con.Open();
_command.Connection = _con;
string _QueryString = "select "+ _SequenceValue +" from dual ";
_command.CommandText = _QueryString;
_ItemValue = Convert.ToInt32(_command.ExecuteScalar().ToString());
_con.Close();
}
catch (Exception ex)
{
Util.LogErrorToFile(ex, "MYExecuteNonQuery", "error");
}
finally
{
_con.Close();
}
return _ItemValue;
}

Chears

{ Comments on this entry are closed }

regular expression for email address validation

by Ali Raza Zaidi on October 20, 2008

hi use this regular expression for email address validation
^[A-Za-z0-9](([_.-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([.-]?[a-zA-Z0-9]+)*).([A-Za-z]{2,})$

Regular expression validator in asp.net would be like

Chears…

{ Comments on this entry are closed }

how to insert dateTime in Oracle database using c#

by Ali Raza Zaidi on September 26, 2008

hi all, i have facing problem while Executing Insert query with dataTime on Oracle database. This query is generated by string manuplation using C# at business layer . i fix the date time as in Query

"TO_DATE('" + ProdMonitor.TRANSACTIONDATE.Month+
"/" + ProdMonitor.TRANSACTIONDATE.Day +
"/" + ProdMonitor.TRANSACTIONDATE.Year+
" " + ProdMonitor.TRANSACTIONDATE.ToLongTimeString()+
"','mm/dd/yyyy HH:MI:SS PM'),"

The Whole Query Will be like

 

Insert Into JOBS (JOB_ID , EXECUTION_TIME,CREATION_TIME,SERIAL_NO,STATUS) values(JOB_ID_SEQ.NEXTVAL,TO_DATE('9/29/2008 11:00:00 PM','mm/dd/yyyy HH:MI:SS PM'),TO_DATE('9/26/2008 12:59:59 PM','mm/dd/yyyy HH:MI:SS PM'),'','1')

Chears

{ Comments on this entry are closed }