ali raza

C#, .Net ,Asp.net and my thoughts

Category Archives: .net framework 2

Best advice for your preparation for 70-536

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 !!!

whats new in asp.net 4.0

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

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);
}

How to get Month name from current date using c#

Hi i found two methods to do so.

Using Globliziation

System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
string month = d.MonthNames[DateTime.Now.Month-1];

Using new date object as follow

string MonthName = GetMonthName(DateTime.Now.Month);
static string GetMonthName(int monthNum)
{
return GetMonthName(monthNum, false);
}
static string GetMonthName(int monthNum, bool abbreviate)
{
if (monthNum < 1 || monthNum > 12)
throw new ArgumentOutOfRangeException(“monthNum”);
DateTime date = new DateTime(1, monthNum, 1);
if (abbreviate)
return date.ToString(“MMM”);
else
return date.ToString(“MMMM”);
}

Chears

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

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
}

how to get oracle sequence numbers in .net

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

How to resize image in .net

use follwing Code change image path at load event method for downloading Code

Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim WorkingDirectory As String = "c:\AliPicture"

'create a image object containing a verticel photograph
Dim imgPhotoVert As Image = Image.FromFile(WorkingDirectory + "\pravs-j-the-first-step.jpg")
Dim imgPhoto As Image = Nothing
imgPhoto = FixedSize(imgPhotoVert, 100, 100)
imgPhoto.Save(WorkingDirectory + "\imageresize_3.jpg", ImageFormat.Jpeg)
imgPhoto.Dispose()

End Sub

Private Shared Function FixedSize(ByVal imgPhoto As Image, ByVal Width As Integer, ByVal Height As Integer) As Image
Dim sourceWidth As Integer = imgPhoto.Width
Dim sourceHeight As Integer = imgPhoto.Height
Dim sourceX As Integer = 0
Dim sourceY As Integer = 0
Dim destX As Integer = 0
Dim destY As Integer = 0

Dim nPercent As Single = 0
Dim nPercentW As Single = 0
Dim nPercentH As Single = 0

nPercentW = (CSng(Width) / CSng(sourceWidth))
nPercentH = (CSng(Height) / CSng(sourceHeight))

'if we have to pad the height pad both the top and the bottom
'with the difference between the scaled height and the desired height
If nPercentH < nPercentW Then
nPercent = nPercentH
destX = CInt(((Width - (sourceWidth * nPercent)) / 2))
Else
nPercent = nPercentW
destY = CInt(((Height - (sourceHeight * nPercent)) / 2))
End If

Dim destWidth As Integer = CInt((sourceWidth * nPercent))
Dim destHeight As Integer = CInt((sourceHeight * nPercent))

Dim bmPhoto As New Bitmap(Width, Height, PixelFormat.Format24bppRgb)
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)

Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
grPhoto.Clear(Color.Red)
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic

grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)

grPhoto.Dispose()
Return bmPhoto
End Function

End Class

how to get server.mappath in c# class

i face a problem that server.mappath did not available in c# class at my utillity framework at app code folder of one of my asp.net application.  While it is available at asp.net page code behind.  Because ASP.NET pages contain a default reference to the System.Web namespace (which contains the
HttpContext class), you can reference the members of HttpContext on an .aspx
page without the fully qualified class reference to HttpContext.

For using Server.MapPath at C# class i used it following

System.Web.HttpContext.Current.Server.MapPath(logpath);

Design Patterns Interview Questions

 

What is a Design Pattern?

Design Pattern is a re-usable, high quality solution to a given requirement, task or recurring problem. Further, it does not comprise of a complete solution that may be instantly converted to a code component, rather it provides a framework for how to solve a problem.

In 1994, the release of the book Design Patterns, Elements of Reusable Object Oriented Software made design patterns popular.

Because design patterns consist of proven reusable architectural concepts, they are reliable and they speed up software development process.

Design Patterns are in a continious phase of evolution, which means that they keep on getting better & better as they are tested against time, reliability and subjected to continious improvements. Further, design patterns have evolved towards targeting specific domains. For example, windows-based banking applications are usually based on singleton patterns, e-commerce web applications are based on the MVC (Model-View-Controller) pattern.

Design Patterns are categorized into 3 types:
Creational Patterns
Structural Patterns
Behavioral Patterns

What are Creational Design Patterns?

The Creational Design Patterns focus on how objects are created and utilized in an application. They tackle the aspects of when and how objects are created, keeping in mind whats the best way these objects should be created.

Listed below are some of the commonly known Creational Design Patterns:
>>> Abstract Factory Pattern
>>> Factory Pattern
>>> Builder Pattern
>>> Lazy Pattern
>>> Prototype Pattern
>>> Singleton Pattern

Whats the difference between Abstract Factory Pattern and Factory Pattern?

In an abstract factory design, a framework is provided for creating sub-components that inherit from a common component. In .NET, this is achieved by creating classes that implement a common interface or a set of interfaces, where the interface comprises of the generic method declarations that are passed on to the sub-components. TNote that not just interfaces, but even abstract classes can provide the platform of creating an application based on the abstract factory pattern.
Example, say a class called CentralGovernmentRules is the abstract factory class, comprised of methods like ShouldHavePolice() and ShouldHaveCourts(). There may be several sub-classes like State1Rules, State2Rules etc. created that inheriting the class CentralGovernmentRules, and thus deriving its methods as well.

Note that the term “Factory” refers to the location in the code where the code is created.

A Factory Pattern is again an Object creation pattern. Here objects are created without knowing the class of the object. Sounds strange? Well, actually this means that the object is created by a method of the class, and not by the class’s constructor. So basically the Factory Pattern is used wherever sub classes are given the priviledge of instantiating a method that can create an object.

Describe the Builder Design Pattern

In a builder design pattern, an object creation process is separated from the object design construct. This is useful becuase the same method that deals with construction of the object, can be used to construct different design constructs.

What is the Lazy Design Pattern?

The approach of the Lazy Design Pattern is not to create objects until a specific requirement matches, and when it matches, object creation is triggered. A simple example of this pattern is a Job Portal application. Say you register yourself in that site thus filling up the registration table, only when the registration table is filled, the other objects are created and invoked, that prompt you to fill in other details too, which will be saved in other tables.

What is the Prototype Design Pattern?

A prototype design pattern relies on creation of clones rather than objects. Here, we avoid using the keyword ‘new’ to prevent overheads.

What is the Singleton Design Pattern?

The Singleton design pattern is based on the concept of restricting the instantiation of a class to one object. Say one object needs to perform the role of a coordinator between various instances of the application that depend on a common object, we may design an application using a Singleton. Usage of Singleton patterns is common in Banking, Financial and Travel based applications where the singleton object consists of the network related information.

A singleton class may be used to instantiate an object of it, only if that object does not already exist. In case the object exists, a reference to the existing object is given. A singleton object has one global point of access to it.

An ASP.NET Web Farm is also based on the Singleton pattern. In a Web Farm, the web application resides on several web servers. The session state is handled by a Singleton object in the form of the aspnet_state.exe, that interacts with the ASP.NET worker process running on each web server. Note that the worker process is the aspnet_wp.exe process. Imagine one of the web servers shutting down, the singleton object aspnet_state.exe still maintains the session state information across all web servers in the web farm.

In .NET, in order to create a singleton, a class is created with a private constructor, and a “static readonly” variable as the member that behaves as the instance.

What are Structural Design Patterns?

A structural design pattern establishes a relationship between entities. Thus making it easier for different components of an application to interact with each other. Following are some of the commonly known structural patterns:

>>> Adapter Pattern – Interfaces of classes vary depending on the requirement.
>>> Bridge Pattern – Class level abstraction is separated from its implementation.
>>> Composite Pattern – Individual objects & a group of objects are treated similarly in this approach.
>>> Decorator Pattern – Functionality is assigned to an object.
>>> Facade Pattern – A common interface is created for a group of interfaces sharing a similarity.
>>> Flyweight Pattern – The concept of sharing a group of small sized objects.
>>> Proxy Pattern – When an object is complex and needs to be shared, its copies are made. These copies are called the proxy objects.

What are the different types of Proxy Patterns?

1 – Remote Proxy – A reference is given to a different object in a different memory location. This may be on a different or a same machine.
2 – Virtual Proxy – This kind of object is created only & only when really required because of its memory usage.
3 – Cache Proxy – An object that behaves as a temporary storage so that multiple applications may use it. For example, in ASP.NET when a page or a user control contains the OutputCache directive, that page/control is cached for some time on the ASP.NET web server.

What is a behavioral design pattern?

Behaviorial design patterns focus on improving the communication between different objects. Following are different types of behavioral patterns:
>>> Chain Or Responsibilities Pattern – In this pattern, objects communicate with each other depending on logical decisions made by a class.
>>> Command Pattern – In this pattern, objects encapsulate methods and the parameters passed to them.
>>> Observer Pattern – Objects are created depending on an events results, for which there are event handlers created.

What is the MVC Pattern (Model View Controller Pattern)?

The MVC Pattern (Model View Controller Pattern) is based on the concept of designing an application by dividing its functionalities into 3 layers. Its like a triad of components. The Model component contains the business logic, or the other set of re-usable classes like classes pertaining to data access, custom control classes, application configuration classes etc. The Controller component interacts with the Model whenever required. The control contains events and methods inside it, which are raised from the UI which is the View component.

Consider an ASP.NET web application. Here, all aspx, ascx, master pages represent the View.

The code behind files (like aspx.cs, master.cs, ascx.cs) represent the Controller.

The classes contained in the App_Code folder, or rather any other class project being referenced from this application represent the Model component.

Advantages: * Business logic can be easily modified, without affecting or any need to make changes in the UI.
* Any cosmetic change in the UI does not affect any other component.

What is the Gang of Four Design Pattern?

The history of all design patterns used in modern day applications derive from the Gang of Four (GoF) Pattern. Gang of Four patterns are categorized into 3 types:
1 – Creational
2 – Structural
3 – Behavioral

The term “Gang of Four” (or “GoF” in acronym) is used to refer to the four authors of the book Design Patterns: Elements of Reusable Object-Oriented Software. The authors are Erich Gamma, Ralph Johnson, Richard Helm and John Vlissides.

When should design patterns be used?

While developing software applications, sound knowledge of industry proven design patterns make the development journey easy and successful. Whenever a requirement is recurring, a suitable design pattern should be identified. Usage of optimal design patterns enhance performance of the application. Though there are some caveats. Make sure that there are no overheads imposed on a simple requirement, which means that design patterns should not be unnecessarily be used.

How many design patterns can be created in .NET?

As many as one can think. Design patterns are not technology specific, rather their foundation relies on the concept of reusability, object creation and communication. Design patterns can be created in any language.

 

 

http://www.dotnetuncle.com/Design-Patterns/dot-net-design-pattern-interview-questions.aspx

Registering ASP.NET on IIS after installing the .NET Framework

Usually this problem occur when we install iIs after installation of Visual studio or .net framework. For this purpose use aspnet_regiis.exe, it is located under %WindowsDir%\Microsoft.NET\Framework\vx.y.zzzz\ and you should call it with the -i parameter: aspnet_regiis.exe -i