Saturday, August 21, 2010

Creating a Setup file/deployment (interface to install a application)

Creation of the interface for installing a windows application or a windows service.
------------------------------------------------------------------------------------

Step1:
--------
Be ready with your .exe file for which you want to create the installation interface/wizard.

Then open VisualStudio and go for new project-->Other projects type -->setup and deployment




Step2:
---------
Then you see the following interface after entering the project............this depends on the version of visual studio you are using.



Step3:
---------



Step4:
--------
Now select the exe file and the config file.
If you dont have any config file then choose only the exe file.


Step5:
---------



Step6:
---------



Step7:
--------



Step8:
--------


Step9:
--------

The final setup exe files are ready in the bin folder.

Creating a perfect sample Windows Service......

Below you can find how to create a windows service and handling all its events for writing a perfect working service and proper CPU consumption by the windows service.


Summary:

The below service is used for creating a file in a specified location and write the time into it at a specific time interval continiously untill you stop the service.




Step1:
-------
Open Visualstudio-->New project-->windows-->service/windowsservice.


Step2:
-------

Now you see the below screen as


step3:
-------
RightClick and choose the add Installer



Step4:
--------
Now you can see the following



Step5:
--------
Now you need to change the properties of the installers..........

Step6:
--------
Now start the coding.


SERVICE1.VB
code:






Imports System
Imports System.IO
Imports System.Configuration

Public Class Service1

'Declaring the global variables
Dim tmTimer As System.Timers.Timer = Nothing

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service.
' in motion so your service can do its work.
'Declaring the variable here
Dim itimeInterval As Integer = -1
Try
'geting time interval from app.config file
itimeInterval = CType(ConfigurationManager.AppSettings("TimeInterval"), Integer)
'initialiasing
tmTimer = New Timers.Timer(itimeInterval)
'starting the timer
tmTimer.Start()
'calling the function when timer finished
AddHandler tmTimer.Elapsed, AddressOf GenerateFile
'again resetting the properties
With tmTimer
.AutoReset = True
.Enabled = True
.Start()
End With
Catch ex As Exception
WriteEventlog(ex.ToString)
End Try
End Sub

Public Sub GenerateFile()
'Declaring the variables
Dim Fs As FileStream = Nothing
Dim Sw As StreamWriter = Nothing
Try
'Creating the objects to the variables
Fs = New FileStream("D:\NewtextFile.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
WriteEventlog("Done creating the file")
Sw = New StreamWriter(Fs)
Sw.WriteLine(DateTime.Now)
WriteEventlog("Done writing the data.")
Sw.Close()
Fs.Close()
Catch ex As Exception
WriteEventlog(ex.ToString)
Finally
Sw.Close()
Fs.Close()
If Sw IsNot Nothing Then Sw = Nothing
If Fs IsNot Nothing Then Fs = Nothing
End Try
End Sub

Private Sub WriteEventlog(ByVal tMsg As String)
'--------------------------------------------------------------------------------------------------
'Description : Logs the entries.
'------------------------------------------------------------------------------------------
Dim MyLog As New EventLog() ' create a new event log

Try
' Check if the the Event Log Exists
If Not Diagnostics.EventLog.SourceExists("File Writing") Then
Diagnostics.EventLog.CreateEventSource("File Writing", "File Writing Log")
End If
MyLog.Source = "File Writing"
' Write the Log
Diagnostics.EventLog.WriteEntry("File Writing Log", tMsg, EventLogEntryType.Information)
Catch ex As Exception

Finally
If MyLog IsNot Nothing Then MyLog = Nothing
End Try
End Sub

Protected Overrides Sub OnStop()
'The event is fired when the service is stopped.
tmTimer.Stop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub

Protected Overrides Sub OnPause()
MyBase.OnPause()
'Handling the paused event of the serivce
tmTimer.Stop()
End Sub
Protected Overrides Sub OnContinue()
MyBase.OnContinue()
''Handling the on continue action of service
tmTimer.Start()
End Sub

Protected Overrides Sub OnShutdown()
MyBase.OnShutdown()
tmTimer.Stop()
End Sub
End Class






*Make sure you write all the events like the onshutdown, onpaused, onstop, onstart for the proper usage of the CPU memory.




The app.config file entry:
---------------------------



here the time is in milliseconds.................so to convert it into minutes, multiply the time with * 60000 and give the value in the below config key


< key ="TimeInterval" value="1">






now build the service. Now your service is ready for installing in services.

Thursday, August 19, 2010

Handling windows services from the code(c#)..........

Wondering how to start, stop, or to get the status of the windows services which are available at SERVICES.MSC.


ASPX CODE:
----------------


.CS code:
-------------

protected void btnStatus_Click(object sender, EventArgs e)
{//declaring the variables
ServiceController scObj = null;
try
{
//creating the object for the service cotroller.
scObj = new ServiceController();
//the service name can be viewed from the: goto RUN->SERVICES.MSC->select a //service->properties->service name.
scObj.ServiceName = "AppHostSvc";

//for stopped state
if (scObj.Status == ServiceControllerStatus.Stopped)
{
lblMsgg.Text = "The service is stopped";
//now we are starting the service
scObj.Start();
}//for running state
else if (scObj.Status == ServiceControllerStatus.Running)
{
lblMsgg.Text = "The service is running.";
//now we are stopping the service
scObj.Stop();
}//for paused state
else if (scObj.Status == ServiceControllerStatus.Paused)
{
lblMsgg.Text = "The service is Paused.";
}

}
catch (Exception Ex)
{
throw Ex;
}
finally
{//clearing the memory
if (scObj != null) scObj = null;
}
}

Monday, August 16, 2010

Directory creation in c# in the selected drives available in your system

Creating a directory in c# in the selected drives available in your system.
----------------------------------------------------------------------------
The below code is used to list all the drives available in your system and allow you to create a directory in the drive you choose.


ASSSUMPTIONS MADE: THE VALIDATION ARE TO BE TAKEN CARE BY YOU.

code:
--------
ASPX:
--------



.cs code
------------

PageLoad event code:


protected void Page_Load(object sender, EventArgs e)
{

//now we need to get the list of the directories of the system
DriveInfo[] diDrive = null;
try
{
if (!IsPostBack)
{
//tdrive = new string[System.IO.DriveInfo.GetDrives().Length];
diDrive = System.IO.DriveInfo.GetDrives();

//arrDrives = System.IO.DriveInfo.GetDrives().ToArray();
ddlDrivesList.Items.Clear();


//here we are adding the drive letters to the dropdown list
foreach (DriveInfo iDrives in diDrive)
{
ddlDrivesList.Items.Add(iDrives.ToString());
}
}
}
catch (Exception)
{

throw;
}
finally
{
if (diDrive != null) diDrive = null;

}


}




Button Click code:



protected void btnCreateDirectory_Click(object sender, EventArgs e)
{
//Declaring the variables here.

try
{
lblerror.Text = string.Empty;
//verifying whether the direactory exists or not
if (System.IO.Directory.Exists(Path.Combine(ddlDrivesList.SelectedItem.ToString(), txtDirectoryName.Text)) == true)
{
lblerror.Text = "Already Exists";
}
else
{
//creating the directory
System.IO.Directory.CreateDirectory(Path.Combine(ddlDrivesList.SelectedItem.ToString(), txtDirectoryName.Text));
lblerror.Text = "directory created";
}
}
catch (Exception EX)
{
throw EX ;
}
}

Sunday, August 15, 2010

Reading Data from the the file (.txt or .csv)

Using the File stream objects to read the data from a file
------------------------------------------------------------
ASSUMPTIONS MADE ARE: THE FILE NAME YOU ARE ENTERING IS EXISTING IN THE ROOT FOLDER OF YOUR APPLICATION. AND VALIDATIONS ARE TAKEN CARE BY YOU.


Code in the .ASPX file
------------------------


Code in .cs file
----------------
protected void btnReadFromFile_Click(object sender, EventArgs e)
{
//declaring the variables required

//we need to use System.IO name space for this.
System.IO.FileStream Fs = null;
System.IO.StreamReader Sr = null;
string tFilePath = string.Empty;
try
{
//gettting the file name as entered by the user
tFilePath = string.Concat(txtFileName.Text.ToString(), ".Txt");

//creating the file stream object
Fs = new System.IO.FileStream(Path.Combine(Server.MapPath("~/"), tFilePath), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read);

//Reading the data into the file
Sr = new System.IO.StreamReader(Fs);
TxtTextToRead.Text = Sr.ReadToEnd();
//closing the streams
Sr.Close();
Fs.Close();

}
catch (Exception ex)
{
throw ex;
}
finally
{
//clearing the memory in the finally block
//Here first we need to close the streams and then make the objects to null
//other wise we get the error some times that the file is accessed by another program
Sr.Close();
Fs.Close();
if (Sr != null) Sr = null;
if (Fs != null) Fs = null;

}

}

How to write data into a Txt or Csv File in C#.NET.

Using the file stream objects for writing the data into the txt file
-----------------------------------------------------------------------------

ASSUMPTIONS MADE ARE:
THE VALIDATIONS ARE NOT DONE HERE, IT MUST BE TAKEN CARE BY YOU.


Code in the .ASPX page
-------------------------





Code in the .cs page
-----------------------
protected void btnWriteIntoFile_Click(object sender, EventArgs e)
{
//declaring the variables required

//we need to use System.IO name space for this.
System.IO.FileStream Fs = null;
System.IO.StreamWriter Sw = null;
string tFilePath = string.Empty;
try
{
//gettting the file name as entered by the user
tFilePath = string.Concat(txtFileName.Text.ToString(),".Txt"); //Change the ext as like(.Txt)

//creating the file stream object
Fs = new System.IO.FileStream(Path.Combine(Server.MapPath("~/"),tFilePath), System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite);

//writing the data into the file
Sw = new System.IO.StreamWriter(Fs) ;
Sw.Write(TxtTextToWriteData.Text.ToString());

//closing the streams
Sw.Close();
Fs.Close();

}
catch (Exception ex)
{
throw ex;
}
finally
{
//clearing the memory in the finally block
//Here first we need to close the streams and then make the objects to null
//other wise we get the error some times that the file is accessed by another program
Sw.Close();
Fs.Close();
if (Sw != null) Sw = null;
if (Fs != null) Fs = null;

}
}

Friday, August 6, 2010

Publish Blog from Word 2007

Publish Blog from Word 2007
Did you know that you can publish directly to your blog from Word 2007? Well, that’s one of the new features of Word 2007! You can publish to popular services such as Blogger, Typepad, Wordpress, Windows Live Spaces and others. All that you need, is internet connection to publish the posts which you have prepared, directly from Word! To start with, you have to create and configure an account in Word and start blogging. You will be able to insert pictures, links, and formatted text as well!
To create and configure an account in Word 2007:
• Click the Office button > Publish > Blog .
• As this is the first time the Blog account is set up, click the Register Now button in the Register a Blog Account dialog.


• In the New Blog Account dialog, select your blog provider- Blogger or WordPress or whatever, from the drop down menu.




* Provide the login details.


* If you would like Word to upload pictures for you, click the Picture Options button.




* You can choose to have Word publish images directly to your blog provider or to your server, if you or a host is serving your site.


Now, you will notice that the Ribbon has changed to blogging mode! You can Publish, Publish as draft, Insert your categories , Open existing posts, set up new blogs and even insert HTML objects like pictures, links and much more! You can even create image effects and drop shadows! Cool!
Now create your blog post and when done, click the Publish button. Your post has been published and live!

Tuesday, July 20, 2010

Filtering the data from datatable using the dataview

How to use a data view in c#

Here is a sample code which shows how to use the dataview in c# for filtering the data


protected void btnSubmit_Click(object sender, EventArgs e)
{
DataSet dsStates = null;
DataView dvRow = null;
try
{
dsStates = new DataSet();
dsStates.ReadXml( Path.Combine(Request.PhysicalApplicationPath , "xmlfile.xml"));
dvRow = dsStates.Tables[0].DefaultView;
dvRow.RowFilter = "state_Text='a'";
TextBox1.Text = dvRow.Table.Rows[0].ItemArray[0].ToString();
}
catch (Exception )
{

throw ;
}
finally
{
dsStates = null;
dvRow = null;
}
}



Description:
From above we are forming the datatable from the xml file, and from the datatable we are filtering the data into the dataview using the dataview's row filter method.


Note:
Good coding practices from the above code are:
1) While combining the path then use the Path.Combine method which is present in the System.IO namespace.
2) Use exceptional handling.
3) Clear the data in the finally block.

Monday, July 12, 2010

ORA-01033: ORACLE initialization or shutdown in progress

This error generally occurs when you newly install the oracle server edition with some improper settings, And you may also get this error when you do some changes in the "ADMINISTATION ASSISTANT FOR WINDOWS" option which comes after installing the oracle server.

The simple solution is:

Sol I:

Login the data base using the sys user, this user is powerful enough to login even the above error occurs (you get an warning message at the time of login- click ok and proceed )
and then type the following query and run it

alter database open

and commit the transaction.


Sol II:
Do the following things

Executed command no & o/p are listed here.


1- SQL> shutdown abort
O/P- ORACLE instance shut down.

2- SQL> start database step by step
O/P- SP2-0310: unable to open file "database.sql"

3- SQL> startup nomount
ORACLE instance started.

Total System Global Area 118255568 bytes
Fixed Size 282576 bytes
Variable Size 83886080 bytes
Database Buffers 33554432 bytes
Redo Buffers 532480 bytes


4- SQL> alter database mount;

Database altered.

5- SQL> alter database open;






OR IF YOU DONT EVEN REMEMBER THE SYS USER PASSWORD, THEN GO TO RUN AND EXECUTE THE FOLLOWING COMMANDS..........


1)
C:\>cd oracle

C:\oracle>

2)

C:\oracle>cd ora92

C:\oracle\ora92>cd bin

C:\oracle\ora92\bin>set ORACLE_SID=OID

C:\oracle\ora92\bin>set ORACLE_HOME=C:\Oracle\ora92


3)
C:\oracle\ora92\bin>sqlplus /nolog

4)
SQL> connect / as sysdba
Connected.



Now you have logged in into the sys user.


And now run this query- Alter database open;

now your database gets opened and now you can login into the database.
SQL>




note: In few systems only 1st step is enough and after that go with the 4th step as :C:\oracle>sqlplus /nolog.


Sunday, June 27, 2010

Running an Applet

A easy way to run a applet inside a browser..........

Create a simple web page which calls the applet which we have created.........the below code is the html code which is used for calling the applet Hello


html start tag
boby start tag

< /applet > tag must be provided here with the proper src.
body end tag
html end tag


We need to make sure that the applet tag is placed only between the body tags.........

This tells the browser to run the applet Hello.class, and to use an area of the screen 500 pixels wide and 300 high. To create the above web page( incase if you are not familiar with the html language) copy paste the above lines into a text document and save it as Hello.html in the same directory that has Hello.class. At this point your directory should look something like this:

C:\> dir A*.*

03/07/98 08:01p 560 Hello.class
03/07/98 08:01p 199 Hello.html
03/07/98 08:00p 247 Hello.java
3 File(s) 1,006 bytes
157,295,104 bytes free

Now double click on the html file. Your Web browser starts running and displays the applet.

Or

you can use the appletviewer to run the applet:

C:\> appletviewer Hello.html

Sometimes browsers are not set up for applets, or have other problems and as a result of this the browser cant open the applet, a error message is displayed saying that "Failed opening the applet. Make sure that the applet-viewer is in the same directory as java and javac and is more reliable for viewing your applets than a Web brower. However, the appletviewer shows you only the applet part of an HTML file. The other parts (if any) are omitted.

Thursday, June 17, 2010

HOW TO OPEN THE BLOCKED SITES

Are you tired of finding the ways to open a website which is blocked by your sysadmin or network administrator.......
Do-not worry as here is a easy and quick solution for opening the site which are blocked

The simplest way is to use a web proxy.

Before that are you eager to know why to go with web proxy?

Anonymous free web proxies are present on the internet, which allows us to bypass local proxies and security restrictions and surf the blocked sites or simply surf securely without any need of installing a software on your computer. If you browse the web through public web proxy the website cannot find your real IP address.

LIST:

24 Proxy

7 N 4
911 Surf
Browse At Work
Browse Orkut
Daves Online Proxy

Diglet

Go Fish
My Proxy Solution

Wednesday, June 16, 2010

RUN COMMAND SHORT_CUTS

USE THE FOLLOWING COMMANDS IN THE RUN COMMAND WINDOW:





Device manager:

hdwwiz.cpl

This is used to open the device manager where you can browse all the types of devices present in your system. The devices listed in this are battery(for laptops), my-computer, HDD disc, display adapters, controllers, keyboard, processors, usb...........etc.


Administrator tools:

control admintools

This command is used for opening the administrator tools used for the controlling purpose. These tools consists or computer-management, event viewer, performance monitor, task scheduler, windows memory diagnostics, windowa fire wall, services, windows power shell.

Blue tooth:

fsquirt

This command opens the blue-tooth transfer wizard.

Componant services:

dcomcnfg

this command is used for the open the interface for the event viewer and the services.

Personalizing the Desktop:

control desktop

This command is used for the setting the personalization of the desktop

Internet configguration wizard:

inetcpl.cpl

This opens the internet configuration wizard.

Mouse property wizard:

control mouse

This command is used for setting or controlling the properties of the mouse.

Key board properties:

control keyboard

this property is used to control or configure properties of the mouse.

To open the access data-base:

access.cpl

This opens the access database corresponding to the database which comes as a part of the MS office.

To open the paint brush:

mspaint

This open the paint brush.

Open notepad:

Notepad

This opens the notepad.


Advanced notepad : (only if installed)

Notepad++

This opens the advances notepad.

Add and remove programs:

Appwiz.cpl

This opens the add and remove program wizard.

Remote desktop login:

mstsc

This opens the login screen to login into the remote system.

Testing the TCP:

tcptest

This command is used for the TCP.


Windows Fire wall wizard:

firewall.cpl

This opens the firewall configuration wizard.




Tuesday, June 15, 2010

Friday, June 11, 2010

HOW TO INSTALL VIRTUAL PC IN WIN 7 HOME PREMIUM

Hi..... Are you wondering how to install virtual pc in windows 7 home premium edition?

Are you tired of searching about how to install a virtual pc with xp compatibility in windows 7 home premium edition...................Don't worry, here is a way of installing the virtual pc with xp compatibility in windows 7 home premium edition.


steps:

1) Do not try to download and install the

"Windows Virtual PC"

as this is not supported in windows 7 home premium edition. (I think you will not be able to even download it from Microsoft site, when trying to download it from a system with operating system as Microsoft windows 7 home premium edition).

2) Download the "MICROSOFT VIRTUAL PC", as this is supported in windows 7 home premium.
Download link for MICROSOFT VIRTUAL PC "http://www.mydigitallife.info/2007/02/21/free-download-microsoft-virtual-pc-2007-with-support-for-windows-vista-as-guest-os/"

Here you can find the versions for 32-bit and 64-bit.

3) Now install this and configure a new virtual PC XP any other os (a list is shown in the dropdown ).

4) After configuring the settings, start the virtual PC then when it will ask for the boot-able disc then insert the disc and then go to the option CD then go for "USE PHYSICAL DRIVE".

5) Now you will be guided through the installation process.

6)And finally you are done with your windows virtual pc with the XP mode or xp compatibility.

NOTE: At the time you are making the configurations for the virtual pc, you will be specifying the ram to be used, this can be changed later also.

Monday, June 7, 2010

LEARN JAVASCRIPT IN 1 HOUR.............JAVASCRIT BASICS..

THIS WORD DOCUMENT IS A NOTES ON BASIC JAVA SCRIPT FUNCTIONS THAT A DEVELOPER MUST KNOW........................THIS DOCUMENT IS ENOUGH TO LEARN JAVASCRIPT BASICS.

find the document at the f0llowing location:

http://www.4shared.com/document/KxTUZXuy/javascriptcourse.html

Saturday, June 5, 2010

Useful Oracle Functions

1) Lead / Lag
Lead function is an analytic function that lets you query
More than one row in a table at a time without having to
Join the table to itself.

It returns values from the next row / Previous Row Respectively in the table.

To return a value from a previous row, try using the lag function.

Example: Business Case.

Need to retrieve the Login date and Last Login date.

Select UserName, LogInDate,
lag (LoginDate,1) over (ORDER BY LoginDate desc) AS prev_Logindate
From UserLoginDetails;

2) Coalesce

coalesce function returns the first non-null expression in the list.
If all expressions evaluate to null, then the coalesce function will return null.

Business Case:

Table has Mobile Number, Land Line, and Office Phone

Three different columns, three fields can be with null values,
We need to retrieve the contact Number for that record,

Select Coalesce ( mobileNumber,Landline,OfficePhone) from Table.

It will return the first not null value from table.


3) NVL2

NVL2 function extends the functionality found in the NVL function.
It lets you substitutes a value when a null value is encountered as well as
When a non-null value is encountered.

Select NVL2( string1, value_if_NOT_null, value_if_null ) As Desc From
MyTable.

All above three functions supports from Oracle version 8i and Above.

Oracle Data Provider for .NET

What is Oracle Data Provider for .NET?

ODP.NET stands for Oracle Data Provider for .NET, ODP.NET is the next step of development technology from Oracle. Seeing the efficiency of data management of the ODP, the application has been developed for better performance through integration.

The Oracle Data Provider for .NET (ODP.NET) features optimized ADO.NET data access to the Oracle database. ODP.NET allows developers to take advantage of advanced Oracle database functionality, including Real Application Clusters, XML DB, and advanced security. The data provider can be used with the latest .NET Framework 3.5 version.

ODP.NET makes using Oracle from .NET more flexible, faster, and more stable. ODP.NET includes many features not available from other .NET drivers, including a native XML data type, self-tuning, RAC optimizations, and Advaned Queuing API.

GET AT A FARE ENOUGH IDEA ABOUT SILVERLIGHT......

Are you new and wondering what is silver light?

What is silver light?
-->Microsoft Silverlight is a web application framework that provides functionalities similar to those in adobe flash, integrating multimedia, graphics, animations and interactivity into a single runtime environment.

You must watch this video to get a clear cut idea of silver light and how easy it is to implement.

http://www.silverlight.net/learn/videos/silverlight-videos/getting-started-with-silverlight-development/

This video is also available for download.

ABOUT ME

Hi All...........I am a DOTNET developer, Please feel free to ask me any doubts regarding DOTNET. In my bog you can find all the stuff related to DOTNET, JAVASCRIPT, OS and other internet stuff.