Sponsored Ad

Saturday, January 30, 2010

MySQL GUI Tools Bundle: Archived Free Downloads

Now MySQL GUI Tools Bundle is freely available for download. you can download it from mySQL site, the link is given below.

 

Users of the MySQL GUI Tools Bundle should plan to upgrade to MySQL Workbench.

MySQL Workbench provides DBAs and developers an integrated tools environment for:

  • Database Design & Modeling
  • SQL Development (replacing MySQL Query Browser)
  • Database Administration (replacing MySQL Administrator)

MySQL GUI Tools: Archived Online Documentation

How to download:

http://dev.mysql.com/downloads/gui-tools/5.0.html

Free Download MySQL Workbench 5.2.15a beta

MySQL Workbench 5.2.15a beta is now freely available for download.

MySQL Workbench provides DBAs and developers an integrated tools environment for:

  • Database Design & Modeling
  • SQL Development (replacing MySQL Query Browser)
  • Database Administration (replacing MySQL Administrator)

The Community (OSS) Edition is available from this page under the GPL.

 

 

How to Download:

http://dev.mysql.com/downloads/workbench/5.2.html

Thursday, January 28, 2010

JavaScript String Variable

This is sample program to demonstrate JavaScript string variable. JavaScript string support verity of string functions here is a demo of length. Length function is used to calculate string length.

 

Code Snippet
  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. // both single & double quote works
  5. var str='College of Computer Science'
  6. document.write("<p>" + str + "</p>")
  7. document.write(str.length)
  8. </script>
  9. </body>
  10. </html>

JavaScript Functions to disable right click on Webpage

Here is full code to disable right click on web page. A user can not copy the content as well as can not see the source code.

Even the user is not able to copy the images.

This is configured for Microsoft internet explorer and Netscape Navigator.

 

Code Snippet
  1.     <html>
  2. <head>
  3. <script language="Javascript1.2">
  4.  
  5. // Set the message for the alert box
  6. am = "This function is not allowed!";
  7.  
  8. bV  = parseInt(navigator.appVersion)
  9. bNS = navigator.appName=="Netscape"
  10. bIE = navigator.appName=="Microsoft Internet Explorer"
  11.  
  12. function nrc(e) {
  13.    if (bNS && e.which > 1){
  14.       alert(am)
  15.       return false
  16.    } else if (bIE && (event.button >1)) {
  17.      alert(am)
  18.      return false;
  19.    }
  20. }
  21.  
  22. document.onmousedown = nrc;
  23. if (document.layers) window.captureEvents(Event.MOUSEDOWN);
  24. if (bNS && bV<5) window.onmousedown = nrc;
  25.  
  26. </script>
  27. <noscript>
  28. <P>Access the <A href="http://valdot.com">data.</A>
  29. </noscript>
  30.  
  31. </head>
  32. <body>
  33. This is a test.
  34. </body>
  35. </html>

Wednesday, January 27, 2010

Free Download Microsoft® Silverligh 3 SDK

image

 

The Microsoft® Silverlight™ 3 SDK contains online documentation, online samples, libraries and tools for developing Silverlight 3 applications.

Supported Operating Systems: Windows 2000 Service Pack 4; Windows 7; Windows Server 2003; Windows Server 2008; Windows Vista; Windows XP

Instructions

Before installing this Silverlight 3 SDK, you need to remove previous Silverlight 3 SDK installed.
Don't install Silverlight additional to Visual Studio 2008, because it is installed with  Visual Studio 2008 by default.

 

How to Download:

http://www.microsoft.com/downloads/details.aspx?familyid=1EA49236-0DE7-41B1-81C8-A126FF39975B&displaylang=en

Free Microsoft Silverlight 3 Offline Documentation:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=0a9773a7-c854-41fa-b73d-535abfb73baf

Free Download Microsoft® Silverlight™ 3 Tools for Visual Studio 2008 SP1

This is patch for Visual Studio 2008 SP1 for developing Silverlight 3 applications.

This Patch is an add-on for Visual Studio 2008 SP1 to provide tooling for Microsoft Silverlight 3. It can be installed on top of either Visual Studio 2008 SP1 or Visual Web Developer 2008 Express with SP1, and it provides a Silverlight project system for developing Silverlight applications using C# or Visual Basic.

This Silverlight 3 Tools for Visual Studio 2008 SP1 includes:

  • Visual Basic and C# Project templates
  • Intellisense and code generators for XAML
  • Debugging of Silverlight applications
  • Remote debugging of Silverlight applications for Mac
  • Web reference support
  • WCF Templates
  • Team Build and command line build support
  • Support for cached transparent platform extensions
  • Support for Silverlight 3 Out-of-Browser applications

 

Supported Operating Systems: Windows 7; Windows Vista; Windows XP Service Pack 3

 

How to Download:

http://www.microsoft.com/downloads/details.aspx?familyid=9442B0F2-7465-417A-88F3-5E7B5409E9DD&displaylang=en

Tuesday, January 26, 2010

Free Download Office Home and Business 2010 Overview

image

 

Microsoft Office Home and Business 2010 is the essential software suite for managing small businesses and working from home. Enhanced tools and features help you run your business, connect with customers, and organize your household more efficiently. Office Home and Business 2010 features new photo, video, and text effects for creating standout documents and presentations. New communication tools in Outlook 2010 help you stay in touch and organized. Office Home and Business 2010 makes it easier than ever for you to manage things in the office, at home, or in between.

 

How to Download:

http://www.microsoft.com/office/2010/en/home-business-edition/default.aspx

Free Download Microsoft Visio Premium 2010 Beta

Free Download Microsoft Visio Premium 2010 Beta

Microsoft Visio Premium 2010 takes diagramming to a bold new level with dynamic, data-driven visualization tools and templates, powerful process-management features, and advanced sharing capabilities through the Web. Bring the big-picture and real-time data from multiple sources, including Microsoft Excel 2010 and Microsoft SQL Server, together in one powerful diagram with vibrant graphics such as icons, colors, and data bars. Manage your processes with sub processes and rules and logic validation to ensure accuracy and consistency across the organization. Using Microsoft SharePoint Server 2010, you can create SharePoint workflows and export them for execution and real-time monitoring.

 

How to Download:

http://technet.microsoft.com/hi-in/evalcenter/ee390821.aspx

Microsoft Visio Premium 2010 Beta System Requirement:

http://technet.microsoft.com/hi-in/library/ee624351(en-us,office.14).aspx#section10

Monday, January 25, 2010

Free Download - Microsoft Windows Identity Foundation

Microsoft Windows Identity Foundation helps simplify user access for developers by externalizing user access from applications via claims and reducing development effort with pre-built security logic and integrated .NET tools. Users can benefit through single sign-on and seamless collaboration across organizational boundaries.

 

Free Download - Microsoft Windows Identity Foundation

 

How to Download:

http://msdn.microsoft.com/hi-in/evalcenter/dd440951.aspx

Free Download - Visual Studio® 2010 Express Beta 2 – Future Version

image

 

The Visual Studio® 2010 Express Beta 2 is a set of free tools which offers you an exciting experience with the new integrated development environment, a new editor built in Windows® Presentation Foundation (WPF) and support for the new .NET Framework 4.

Powerful Set of Free Tools
Choose the language that's right for you.

Microsoft® Visual Basic® 2010 Express is ideal for the

developer learning to program on Microsoft® Windows®.

Microsoft® Visual Web Developer® 2010 Express is an easy to use

environment for dynamic Web application development.

Microsoft® Visual C#® 2010 Express offers a greater

combination of power and productive for Windows developers building on .NET.

Microsoft® Visual C++® 2010 Express provides

developers the horsepower with a finer degree of control than the other Visual Studio Express productions.

 

How to Download:

http://www.microsoft.com/express/Express-2010/

image

image

Sunday, January 24, 2010

Free Download the Windows Azure Software Development Kit

Free Download the Windows Azure Software Development Kit

Windows Azure is a cloud services operating system that serves as the development, service hosting and service management environment for the Windows Azure platform. Windows Azure provides developers with on-demand compute and storage to host, scale, and manage Web applications on the Internet through Microsoft data centers.

 

Use Windows Azure to:

  • Add Web service capabilities to existing packaged applications
  • Build, modify, and distribute applications to the Web with minimal on-premises resources
  • Perform services (large-volume storage, batch processing, intense or large-volume computations, etc.) off premises
  • Create, test, debug, and distribute Web services quickly and inexpensively
  • Reduce costs of building and extending on-premises resources
  • Reduce the effort and costs of IT management

 

How to Download:

http://msdn.microsoft.com/hi-in/evalcenter/ee460823.aspx

Visual Studio 2010 beta 1 installation for Windows XP

 

Download VS2010 beta from

http://msdn.microsoft.com/hi-in/vstudio/dd582936(en-us).aspx

 

Click on Visual studio 2010 Setup icon.

vs2010 setupVisual Studio 2010 beta 1 installation for Windows XP

 

Select Install Visual Studio 2010 from setup Screen.

vs2010 setup

 

After loading the setup files click on next button to proceed setup.

vs2010 enter key

 

Enter the product key and name of organization and click next.

Enter the product key and name of organization and click next.

 

Now setup will restart the system 2-3 times and setup complete screen will appear.  Now install the OS and visual studio updates.

vs2010 install updates

Friday, January 22, 2010

Visual Studio 2010 Express (Beta 2) Free Download

Visual Studio 2010 Express (Beta 2) Free Download

 

The Visual Studio® 2010 Express Beta 2 is a set of free tools which offers you an exciting experience with the new integrated development environment, a new editor built in Windows® Presentation Foundation (WPF) and support for the new .NET Framework 4.

Powerful Set of Free Tools

 

Choose the language that's right for you.

Microsoft® Visual Basic® 2010 Express is ideal for the

developer learning to program on Microsoft® Windows®.

Microsoft® Visual Web Developer® 2010 Express is an easy to use

environment for dynamic Web application development.

Microsoft® Visual C#® 2010 Express offers a greater

combination of power and productive for Windows developers building on .NET.

Microsoft® Visual C++® 2010 Express provides

developers the horsepower with a finer degree of control than the other Visual Studio Express productions.

 

Visual Studio 2010 Express (Beta 2) Main Page:

http://www.microsoft.com/express/Express-2010/

Visual Studio 2010 Express (Beta 2) Download Location:

 

http://www.microsoft.com/express/Downloads/#Visual_Studio_2010_Express_Downloads

SQL Server 2008 Express Free Download

image

 

A lightweight, feature-rich, powerful database for Windows and Web data-enabled needs.

Easy to get. Free to use.

  • Available free!
  • Quickly build and deploy your database solution.
  • Backup and restore with ease.
  • Available with a graphical management tool, reporting capabilities and full-text search.
  • Ideal for building Web sites and apps, small scale LOB solutions or for redistribution with ISV applications.

 

Download Location:

http://www.microsoft.com/express/Database/

How to Install SQL Server 2008 Express Edition with Tools

Visual Studio 2008 Express Editions Free Download

Visual Studio 2008 Express Editions Free Download

Visual Studio 2008 Express Editions are free development tools.
Register your product within 30 days from installation.

  • Visual Basic 2008 Express Edition
  • Visual C# 2008 Express Edition
  • Visual C++ 2008 Express Edition
  • Visual Web Developer 2008 Express Edition
  • All - Offline Install ISO image file
  • MSDN Express Library
Powerful Set of Free Tools

Microsoft® Visual Web Developer® 2008 Express Edition provides you with everything you need to start building standards-friendly Web applications.

SQL Server® 2008 Express Edition is a lightweight, feature-rich, powerful database for your Web data-enabled needs.

Easily add Search Engine Optimization (SEO) to your site with the Free SEO Toolkit, which is included in the Microsoft Web Platform Installer.

 

Download Location:

http://www.microsoft.com/express/Downloads/#2008-Web-Platform-Installer

Microsoft .NET Framework 3.5 Service Pack 1 – Free Download

Microsoft .NET Framework 3.5 Service Pack 1 – Free Download

Microsoft .NET Framework 3.5 Service Pack 1 is a full cumulative update that contains many new features building incrementally upon .NET Framework 2.0, 3.0, 3.5, and includes cumulative servicing updates to the .NET Framework 2.0 and .NET Framework 3.0 subcomponents.

 

Download Location:

http://www.microsoft.com/downloads/details.aspx?familyid=ab99342f-5d1a-413d-8319-81da479ab0d7&displaylang=en

Free Microsoft Press E-Book (Visual Studio 2008) Offer

 

Just Sign up to download the All the chapters!

 

image

Programming Microsoft LINQ
by Paolo Pialorsi and Marco Russo
ISBN: 9780735624009

  • Chapter 6: Tools for LINQ to SQL
  • Chapter 16: LINQ and ASP.NET

 

image

Introducing Microsoft® SilverlightTM 2, Second Edition
by Laurence Moroney
ISBN: 9780735625280

  • Chapter 1: Introducing Silverlight 2
  • Chapter 2: Using Expression Blend with Silverlight 2

 

image

Programming Microsoft® ASP.NET 3.5
by Dino Esposito
ISBN: 9780735625273

  • Chapter 3: Anatomy of an ASP.NET Page
  • Chapter 18: HTTP Handlers and Modules

 

Download Link:

http://csna01.libredigital.com/?urvs5cn3s8

Visual Studio 2008 - 90-Day Trial Downloads – Free Download

Visual Studio 2008 - 90-Day Trial Downloads

Microsoft Visual Studio 2008 provides an industry-leading developer experience for Windows Vista, the 2007 Microsoft Office system, and the Web. In addition, it continues in the Microsoft tradition of development language innovation. To enable evaluation of Visual Studio 2008, this page provides links to trial editions of Visual Studio 2008. For more information, see Visual Studio 2008 Product Information.

Visual Studio 2008 Main Page:

http://msdn.microsoft.com/hi-in/vstudio/aa700831.aspx

Visual Studio 2008 - Trial Software

http://msdn.microsoft.com/hi-in/vstudio/products/cc268305(en-us).aspx

Visual Studio Team System 2008 - Trial Software

http://msdn.microsoft.com/hi-in/vsts2008/products/cc268310(en-us).aspx

CodeRush Xpress for C# and Visual Basic inside Visual Studio 2008 Free Download

CodeRush Xpress is a powerful developer productivity tool from Dev Express. The product is free, licensed by Microsoft on behalf of all developers working in Visual Studio 2008 in all paid-for product skus (e.g., Standard, Professional, Team System). Note however that CodeRush Xpress will not load in the Express Editions of Visual Studio.

CodeRush Xpress includes features that support common developer tasks in the following areas: Navigate, Declare, Select, and Refactor.

CodeRush Xpress Main Page:

http://msdn.microsoft.com/en-us/vcsharp/ee663901.aspx

CodeRush Xpress Direct Download:

http://www.devexpress.com/go/CodeRushX.aspx

CodeRush Xpress 9.1 - Features for C# Developers Video Tutorial

http://tv.devexpress.com/CRX91FeaturesCS.movie

CodeRush Xpress 9.1 - Features for VB Developers Video Tutorial

http://tv.devexpress.com/CodeRushXpressVBIntro.movie

 

Using CodeRush Templates for Smart Code Generation

 

Tuesday, January 19, 2010

Exception handling in Oracle

Here is sample code you can use in Oracle Procedure, Package, Function or Trigger.

SQLERRM is a oracle keyword and contains the error message, you need to store this message for debugging purpose. SQLCODE is also a keyword and used to find out error details. There are number of ways you can store error message.

1. Store in Global Temporary Table
2. Return Values either Through Cursor or String.
3. use dbms_output.put_line( v_Error)

As per my Experience, Global Temporary table works well.

 

Code Snippet
  1. DECLARE
  2.     N_COUNT  number := 0;
  3.     v_Error varchar2(4000) := '';
  4.     BEGIN
  5.  
  6.        --Body Part Logic
  7.  
  8.     EXCEPTION
  9.        WHEN OTHERS THEN
  10.            v_Error := sqlerrm;  
  11.            v_code := SQLCODE;     
  12.            
  13.     END;

 

Handling Specific Exceptions:

 

Code Snippet
  1. BEGIN
  2.  
  3.     EXCEPTION
  4.       WHEN ZERO_DIVIDE THEN
  5.         dbms_output.put_line('Failure : ' || sqlerrm);
  6.     END;

 

Predefined (Named) PL/SQL Exceptions

Exception Name

Error

Description

ACCESS_INTO_NULL

ORA-06530

Attempted to assign values to the attributes of an uninitialized (NULL) object

CASE_NOT_FOUND

ORA-06592

None of the choices in the WHEN clauses of a CASE statement is selected and there is no ELSE clause

COLLECTION_IS_NULL

ORA-06531

Attempt to apply collection methods other than EXISTS to an uninitialized (NULL) PL/SQL table or varray

CURSOR_ALREADY_OPEN

ORA-06511

Exactly what it seems to be. Tried to open a cursor that was already open

DUP_VAL_ON_INDEX

ORA-00001

An attempt to insert or update a record in violation of a primary key or unique constraint

INVALID_CURSOR

ORA-01001

The cursor is not open or not valid in the context in which it is being called

INVALID_NUMBER

ORA-01722

It isn't a number even though you are treating it like one to trying to turn it into one

LOGIN_DENIED

ORA-01017

Invalid name and/or password for the instance

NO_DATA_FOUND

ORA-01403

The SELECT statement returned no rows or referenced a deleted element in a nested table or referenced an initialized element in an Index-By table

NOT_LOGGED_ON

ORA-01012

Database connection lost

PROGRAM_ERROR

ORA-06501

Internal PL/SQL error

ROWTYPE_MISMATCH

ORA-06504

The rowtype does not match the values being fetched, or assigned, to it

SELF_IS_NULL

ORA-30625

Program attempted to call a MEMBER method, but the instance of the object type has not been intialized. The built-in parameter SELF points to the object, and is always the first parameterpassed to a MEMBER method

STORAGE_ERROR

ORA-06500

A hardware problem: Either RAM or disk drive

SUBSCRIPT_BEYOND_COUNT

ORA-06533

Reference to a nested table or varray index higher than the number of elements in the collection

SUBSCRIPT_OUTSIDE_LIMIT

ORA-06532

Reference to a nested table or varray index outside the declared range (such as -1)

SYS_INVALID_ROWID

ORA-01410

The conversion of a character string into a universal rowid fails because the character string does not represent a valid rowid

TIMEOUT_ON_RESOURCE

ORA-00051

The activity took too long and timed out

TOO_MANY_ROWS

ORA-01422

The SQL INTO statement brought back more than one value or row (only one is allowed)

USERENV_COMMITSCN_ERROR

ORA-01725

Added for USERENV enhancement, bug 1622213

VALUE_ERROR

ORA-06502

An arithmetic, conversion, truncation, or size-constraint error. Usually raised by trying to cram a 6 character string into a VARCHAR2(5) variable

ZERO_DIVIDE

ORA-01476

Not only would your math teacher not let you do it. Computer's won't either. Who said you didn't learn anything useful in primary school

Monday, January 18, 2010

VB.NET To C#.NET Code Converter, C#.NET To VB.NET Code Converter,

This service will translate the code for you, just start typing the code or upload a file to convert it.

Here is the links where you can find the C#.NET to VB.NET Code converter and VB.NET  to C#.NET Code converter

  1. Start typing your code.
  2. Copy and Paste the code in the Code Text Box.
  3. Click on Translate  button.

http://www.developerfusion.com/tools/convert/csharp-to-vb/

http://converter.telerik.com/

http://www.carlosag.net/Tools/CodeTranslator/

Tuesday, January 12, 2010

Split Comma Separated Values Using Oracle Function

There are number of ways to split comma separated values. This is very simple method to separate the comma separated or any other separated string. you can change the delimiter as per your requirement. This method have a limitation that string can not exceed the 4000 characters.

if you want  a functionality more than 4000 characters, Please go for long input values also use packages instead of procedures, because functions do not support long parameter type.

Please comment for any issues/Questions.

 

Code Snippet
  1. CREATE OR REPLACE FUNCTION FNC_SPLIT( p_list varchar2, p_del varchar2 := ',') return tp_split_tbl pipelined
  2.     is
  3.         l_idx    pls_integer;
  4.         l_list    varchar2(32767) := p_list;
  5.         
  6.     begin
  7.         loop
  8.             l_idx := instr(l_list,p_del);
  9.             if l_idx > 0 then
  10.                 pipe row(substr(l_list,1,l_idx-1));
  11.                 l_list := substr(l_list,l_idx+length(p_del));
  12.  
  13.             else
  14.                 pipe row(l_list);
  15.                 exit;
  16.             end if;
  17.         end loop;
  18.         return;
  19.     end ;

 

How to call function:

 

Code Snippet
  1. SELECT NVL(COLUMN_VALUE, '') emp_name
  2.     FROM TABLE(FNC_SPLIT(comma_separated_string, ','))

The above function returns the pipeline table, you can use a temporary table to insert the values.

How to combine values into Comma Separated string using Oracle function, Convert selected values into comma separated string

This is function to convert values into comma separated string. This function takes input as cursor and joining delimiter and return a string. This code supports oracle 8 and above. One can test for lower versions also.

Please let me know if you face any problem.

Code Snippet
  1. CREATE OR REPLACE FUNCTION Fnc_JOIN
  2. (
  3.     p_cursor sys_refcursor,
  4.     p_del VARCHAR2 := ','
  5. ) RETURN VARCHAR2
  6. IS
  7.     l_value   VARCHAR2(32767);
  8.     l_result  VARCHAR2(32767);
  9. BEGIN
  10.     LOOP
  11.         FETCH p_cursor INTO l_value;
  12.         EXIT WHEN p_cursor%NOTFOUND;
  13.         IF l_result IS NOT NULL THEN
  14.             l_result := l_result || p_del;
  15.         END IF;
  16.         l_result := l_result || l_value;
  17.     END LOOP;
  18.     RETURN l_result;
  19. END ;

 

How to call This function:

 

Code Snippet
  1. select fnc_join(cursor (SELECT emp_name FROM emp_table)) from dual;

 

One can change the concatenation delimiter to any other character as per requirement.

Monday, January 11, 2010

ASP.NET Ajax Library Beta Free Download

Microsoft Web Platform Installer 2.0 Free Download

You can use the ASP.NET Ajax Library Beta with both ASP.NET Web Forms and ASP.NET MVC applications. If you want to use the ASP.NET UpdatePanel and ScriptManager with ASP.NET 2.0, refer to this page for the ASP.NET AJAX Extensions 1.0 release and other downloads, or upgrade to ASP.NET 3.5 SP1.

 

How to download:

http://www.asp.net/AJAX/Downloads/

Microsoft Web Platform Installer 2.0 Free Download

Microsoft Web Platform Installer 2.0 Free Download

 

The Microsoft Web Platform Installer 2.0 (Web PI) is a free tool  that helps to get latest components of the Microsoft Web Platform, including internet Information Services (IIS), SQL Server Express,. NET Framework and Visual Web Developer etc. The Internet IP also makes it easy to install and run the most popular free web applications for blogs, content management and more with the built-in Windows applications.

 

To visit application gallery:

http://www.microsoft.com/web/gallery/

 

How to Download:

http://www.microsoft.com/web/downloads/platform.aspx

Thursday, January 7, 2010

C# Interview Questions

Method and Property

1. How is method overriding different from method overloading?

When overriding a method, you alter the behavior of the method for the derived class. Overloading a method basically involves having another method with the same name within the class.

2. Can you declare an override method to be static if the original method is not static?

No. The signature of the virtual method must remain the same. (Note: only the keyword virtual is changed to keyword override).

3. What are the different ways a method can be overloaded?

Different parameter information types, different number of parameters, different order of parameters.

4. If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Yes, the place of two points, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Events and Delegates

1. What’s a delegate?

A delegate object encapsulates a reference to a technique.

2. What’s a multicast delegate?

A delegate that has multiple handlers assigned to it. Each assigned handler (process) is called.

Debugging and Testing

3. What debugging tools come with the .NET SDK?

Cordbg - command-line debugger. Cordbg To use, you must compile the original C # using the / debug.

2. DbgCLR - graphic debugger. Visual Studio. NET uses the DbgCLR.

4. What does assert() method do?

In debug compilation, assert themselves in a Boolean condition as a parameter, and displays the error dialog if the condition is false. The program continues without interruption if the condition is true.

5. What’s the difference between the Debug class and Trace class?

Documentation looks the same. Use Debug class for debug, use Trace class for debug and release builds.

6. Why are there five tracing levels in System.Diagnostics.TraceSwitcher?

The tracing dumps can be verbose. For applications that are constantly jogging you run the risk of overloading the machine and the hard drive. Two levels range from None to Verbose, allowing you to adjust the tracing activities.

7. Where is the output of TextWriterTraceListener redirected?

To the Console or a text file depending on the parameter passed to the constructor. 

8. How do you debug an ASP.NET Web application?

Attach the aspnet_wp.exe process to the DbgClr debugger. 

9. What are three test cases you should go through in unit testing?

1. Positive check cases (correct information, correct output).

2. Negative check cases (broken or missing information, proper handling).

3. Exception check cases (exceptions are thrown and caught properly).

Wednesday, January 6, 2010

Unit Testing using Dummy Datatable, An Additional Approach

The main purpose of unit testing is to take the smallest piece of testable application in the application, isolate it from the rest of the code and decide if it behaves exactly as expected. Each unit is tested separately before integrating them into the modules to check the interfaces between modules. Unit testing has proven its value in which a huge percentage of defects identified during use.

One simple approach is  to make a dummy dataset and data table, give the same column name and try to fill similar kind of values in dataset and table. now use this dataset as sample and test your code with this input.

Please let us know if you feel any problem in making a dataset and testing with it. I like queries and questions. Please ask me.

 

Code Snippet
  1. public DataTableGetUTLogs()
  2.       {
  3.           DataTable dt = new DataTable();
  4.           try
  5.           {
  6.               //Log_Id
  7.               dt.Columns.Add(new DataColumn("log_id",Type.GetType("System.String")));                
  8.               //Log_Type
  9.               dt.Columns.Add(new DataColumn("log_type",Type.GetType("System.String")));
  10.               //name
  11.               dt.Columns.Add(new DataColumn("name",Type.GetType("System.String")));
  12.  
  13.               dt.AcceptChanges();
  14.               DataRow dr = dt.NewRow();
  15.  
  16.               //First Row
  17.               dr["log_id"]="12379";
  18.               dr["name"]="xyz inc.";
  19.               dr["log_type"]="ON";
  20.               
  21.               dt.Rows.Add(dr);
  22.               dt.AcceptChanges();
  23.  
  24.               //Second Row
  25.               dr=null;
  26.               dr=dt.NewRow();
  27.               dr["log_id"]="13380";
  28.               dr["name"]="usa inc.";
  29.               dr["log_type"]="OFF";
  30.               
  31.               dt.Rows.Add(dr);
  32.               dt.AcceptChanges();
  33.  
  34.               //Third Row
  35.               dr=null;
  36.               dr=dt.NewRow();
  37.               dr["log_id"]="12281";
  38.               dr["name"]="abcd inc.";
  39.               dr["log_type"]="ON";
  40.               
  41.               dt.Rows.Add(dr);
  42.               dt.AcceptChanges();
  43.           
  44.               return dt;
  45.           
  46.           }
  47.           catch(Exception ex)
  48.           {
  49.               throw;
  50.           }
  51.           finally
  52.           {
  53.               if(dt != null)
  54.               {
  55.                   dt =null;
  56.               }
  57.           }
  58.       }

Get Execution Path Shared by Web application and Windows application Using c#

This method will return a execution path of either web application or Windows application, Depend on from where we calling.

 

Code Snippet
  1. /// <summary>
  2.     /// This method will retunrns the execution path of our application.
  3.     /// This method returns execution path for web application as well as windows service.
  4.     /// </summary>
  5.     /// <returns>Returns <see cref="System.String"/> value.</returns>
  6.     public static string GetExecutionPath()
  7.     {
  8.         string ExecutionPath = "";
  9.         try
  10.         {
  11.             ExecutionPath = System.Web.HttpContext.Current.Server.MapPath("ServiceConfig.xml");
  12.         }
  13.         catch
  14.         {
  15.         }
  16.         if (ExecutionPath == "")
  17.         {
  18.             ExecutionPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  19.         }
  20.         try
  21.         {
  22.             string strExeName = FileSystem.Dir(ExecutionPath, 0);
  23.             string FilePath = Path.GetFullPath(ExecutionPath.Substring(0, (ExecutionPath.Length - strExeName.Length)));
  24.  
  25.             return FilePath;
  26.         }
  27.         catch
  28.         {
  29.             throw;
  30.         }
  31.     }

While “ServiceConfig.xml” is a configuration file kept in root of web application and windows application.

How to Purge Files From a Given Directory Using c#

This method purge all files in current execution path, which are older than  10 days.

This method usage the another user defined method to get the execution path. This method delete all the files from the execution path directory which are older than the given days. you can change the number of days and also hard code the execution path.

Please let us know if you face any problem in implementing the given scenario.

Please note that this method will delete only *.log files from the given directory, you can change the file type from the code.

Code Snippet
  1. /// <summary>
  2.     /// This method purge all files in current execution path, which are older than  DaysToKeepHistory.
  3.     /// </summary>
  4.     public static void PurgeOldFiles()
  5.     {
  6.         int intNoOfDays;
  7.         DateTime TodaysDate;
  8.         DirectoryInfo dir = null;
  9.         FileInfo[] Files = null;
  10.        
  11.         try
  12.         {
  13.             intNoOfDays = 10;
  14.             TodaysDate = DateTime.Now.Date;
  15.  
  16.             dir = new DirectoryInfo(GetExecutionPath());
  17.             Files = dir.GetFiles("*.log");
  18.  
  19.             foreach (FileInfo LogF in Files)
  20.             {
  21.                 if (DateTime.Compare(TodaysDate, LogF.LastWriteTime.AddDays(intNoOfDays)) >= 0)
  22.                 {
  23.                     LogF.Delete();
  24.  
  25.                 }
  26.             }
  27.  
  28.         }
  29.         catch (Exception ex)
  30.         {
  31.            // Unable to purge Files : Message :  ex.Message
  32.             
  33.         }
  34.         finally
  35.         {
  36.             if (dir != null)
  37.             {
  38.                 dir = null;
  39.             }
  40.             if (Files != null)
  41.             {
  42.                 Files = null;
  43.             }
  44.         }
  45.  
  46.     }
 

 

Code Snippet
  1. /// <summary>
  2.     /// This method will retunrns the execution path of our application.
  3.     /// This method returns execution path for web application as well as windows service.
  4.     /// </summary>
  5.     /// <returns>Returns <see cref="System.String"/> value.</returns>
  6.     public static string GetExecutionPath()
  7.     {
  8.         string ExecutionPath = "";
  9.         try
  10.         {
  11.             ExecutionPath = System.Web.HttpContext.Current.Server.MapPath("ServiceConfig.xml");
  12.         }
  13.         catch
  14.         {
  15.         }
  16.         if (ExecutionPath == "")
  17.         {
  18.             ExecutionPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  19.         }
  20.         try
  21.         {
  22.             string strExeName = FileSystem.Dir(ExecutionPath, 0);
  23.             string FilePath = Path.GetFullPath(ExecutionPath.Substring(0, (ExecutionPath.Length - strExeName.Length)));
  24.  
  25.             return FilePath;
  26.         }
  27.         catch
  28.         {
  29.             throw;
  30.         }
  31.     }

 

While “ServiceConfig.xml” is a configuration file kept in root of web application and windows application.

How to Download File From FTP Server in C#, C# Source Code to Download File from FTP

Thanks to the  .NET Framework  2.0 , all the basic functionality to access an FTP server is already built into C #.

This method downloads file from FTP and add date time to new File name.

 

Key points

  • Each application will require an object attached to its NetworkCredentials Credentials property. This tells the application how to authenticate against the FTP server.
  • The URI provided in order of application must include the name of the file you need to load or unload. For example, if we are downloading the file "data.xml" of abc.ftp.com our ftp://abc.ftp.com/data.xml URI.
  • You need to be familiar with the Stream object. We will use this object, both upload and download files.
  • These can be simple, when I started moving files to / from FTP servers do not understand some of these concepts, so I thought it would be important! Now go to the code.

Steps to follow


   1. Create ftp object
   2. Login to ftp server using userid and password
   3. Set keepalive property true to multiple use of same instance 
   4. Use binary method to upload data
   5. Set action to check the date and time of ftp file
   5. Call our used defined method to download file
   6. Open file in filesteam
   7. Read the FTP file in buffer
   8. Save file at local drive

 

Code Snippet
  1. public void DownloadFile(string ftppath, string destfile,string strFileName)
  2.     {
  3.         try
  4.         {
  5.             //create ftp object
  6.             FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftppath);
  7.             //userid and password for the ftp server
  8.             ftp.Credentials = new NetworkCredential("ftp_username", "ftp_password");
  9.             //Set keepalive property true to multiple use of same instance  
  10.             ftp.KeepAlive = true;
  11.             //use binary method to upload data
  12.             ftp.UseBinary = true;
  13.             //set action to check the date and time of ftp file
  14.             ftp.Method = WebRequestMethods.Ftp.GetDateTimestamp;
  15.              FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
  16.             //recieve ftp file date time
  17.             DateTime modification = response.LastModified;
  18.  
  19.             // Download the data
  20.              string sBackupFileName = strFileName + modification.ToString("MM_dd_yyyy") + "_" + modification.Hour.ToString() + "_" + modification.Minute.ToString() + "_" + modification.Second.ToString() + ".xml";
  21.             //download file in byte , for this call another user defined method given in this post
  22.             byte[] Data = DownloadData(ftppath);
  23.  
  24.             // Save the data to disk
  25.             FileStream fs = new FileStream(destfile + sBackupFileName, FileMode.Create);
  26.  
  27.             fs.Write(Data, 0, Data.Length);
  28.             //close the file stream
  29.             fs.Close();
  30.         }
  31.         catch (Exception ex)
  32.         {
  33.             //exception handling
  34.             throw;
  35.         }
  36.  
  37.     }

 

Code Snippet
  1. //user define method to download data from FTP
  2.    public byte[] DownloadData(string path)
  3.   {
  4.       // Get the object used to communicate with the server.
  5.       WebClient request = new WebClient();
  6.  
  7.       // Logon to the server using username + password
  8.       ftp.Credentials = new NetworkCredential("ftp_username", "ftp_password");
  9.  
  10.       return request.DownloadData(path);
  11.   }

 

How to call method:

DownloadFile("ftp://abc.ftp.com/data.xml", Server.MapPath("/abc/Documents/"), "new_file");

Tuesday, January 5, 2010

How to use C# to upload files to FTP, C# File Upload Source Code

FTP File upload through C#

Many applications need the ability to upload and download files via FTP. Even automated processes regularly interact with FTP servers for transferring information. Recognizing this, Microsoft has given developers a straight forward technique to implement this functionality. This document focuses on showing the easy way to take advantage of what Microsoft has provided in the. NET Framework.

Before coming to move files around, put a few things to light:

Key points

  • Each application will require an object attached to its NetworkCredentials Credentials property. This tells the application how to authenticate against the FTP server.
  • The URI provided in order of application must include the name of the file you need to load or unload. For example, if we are downloading the file "data.xml" of abc.ftp.com our ftp://abc.ftp.com/data.xml URI.
  • You need to be familiar with the Stream object. We will use this object, both upload and download files.
  • These can be simple, when I started moving files to / from FTP servers do not understand some of these concepts, so I thought it would be important! Now go to the code.

Steps to follow


    1. Create ftp object
    2. Login to ftp server using userid and password
    3. Set keepalive property true to multiple use of same instance 
    4. Use binary method to upload data
    5. Set action upload or download
    6. Open file in filesteam
    7. Read the file in buffer
    8. close the filesteam
    9. now open ftpsteam
    10.write buffer at ftp
    11.close the ftp stream

here ftpfilepath is full path of file including file name. and in our case its ftp://abc.ftp.com/data.xml

 

Code Snippet
  1. public void ftpUpload(string ftpfilepath, string inputfilepath)
  2.     {
  3.         try
  4.         {
  5.             //create ftp object
  6.             FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfilepath);
  7.  
  8.             //  ftp.Credentials = new NetworkCredential("anonymous", "anonymous");
  9.             //userid and password for the ftp server
  10.             ftp.Credentials = new NetworkCredential("ftp_username", "ftp_password");
  11.             //Set keepalive property true to multiple use of same instance  
  12.             ftp.KeepAlive = true;
  13.             //use binary method to upload data
  14.             ftp.UseBinary = true;
  15.             //set action (upload or download
  16.             ftp.Method = WebRequestMethods.Ftp.UploadFile;
  17.             //open file in filesteam
  18.             FileStream fs = File.OpenRead(inputfilepath);
  19.             byte[] buffer = new byte[fs.Length];
  20.             //read the file in filestream
  21.             fs.Read(buffer, 0, buffer.Length);
  22.             //close the filesteam
  23.             fs.Close();
  24.             //now open ftpsteam
  25.             Stream ftpstream = ftp.GetRequestStream();
  26.             //write at ftp
  27.             ftpstream.Write(buffer, 0, buffer.Length);
  28.             //close the ftp stream
  29.             ftpstream.Close();
  30.  
  31.         }
  32.         catch (Exception ex)
  33.         {
  34.             //handle exceptions
  35.             throw;
  36.         }
  37.     }

 

 

How to call function

ftpUpload("ftp://abc.ftp.com/data.xml", Server.MapPath("/abc/Documents/") + "temp.xml");

Sponsored Ad

More Related Articles

Website Update

Followers