Archive

Archive for July, 2008

Get User desktop folder path in C#

July 16th, 2008 Shyju No comments

How to Get the Path to the User desktop in C#.NET ? Here is the single line Code

string strPath=Environment.GetFolderPath(System.Environ

ment.SpecialFolder.DesktopDirectory).ToString();

OUTPUT looks like this..

F:\Documents and Settings\Shyju\Desktop

Setting PATH while Installing an Application – Visual Studio 2005 Setup project

July 9th, 2008 Shyju 2 comments

A Small stuff to explain how to set the path variable for our executable’s Application folder.So that we can call the executable from anywhere in the PC ,(like invoking the notepad application from the PC,by command prompt).

Start……????????

Create a Project for Your Actual requirement.Write code for the functionalities u want to run when the user run the executable on the machine.Once You finish it,You can add a deployment Setup project to this project.for this Go to File->Add->New Project.Then a Dialog box will appear and from there we can select the Other Project types->Setup wizard.This Project will be added to the Available Project and Hence a Solution will be created and both of the projects will be comes under the Solution.

I hope you guys know how to Go ahead with the deployment creation wizard.very simple.Only thing u need to do is clicking the proper NEXT buttons !

Solution Explorer with 2 projects

Now When u build the Projects,You will get the Installable stuff.You can find this in your project’s(Deployment Setup project) Debug directory.The file name will be having an .msi extension.

Project Setup output

You can run this installer program in your pc and it will install our Application in it.

If you go to the Application folder ,You can see the executable there.

exe in progrm files

You can double click on the exe file to run it.

we can run the program from Commandprompt too.But for that we have to traverse through the folders using cd command.
Now we are going to make some changes to an environment variable for running our new executable.There is an environment variable called “Path” ,Where we will map some folder locations where the system has to search for some executables when a call for the exe comes.

for example,if we are typing notepad in command line, a new Notepad application will be launched.how it came ?Here comes the significance of “PATH”.The Full address of the notepad.exe has been mapped in the Path variable.so when the system get a call to the executable.It will look in to the Folders which are mapped in PATH.

Now we are going to Set the path for our exe in the system environment variable.
For that we will create another DLL and this dll will be called when the User installs our application

So we can add another project to our existing Solution.
File->Add->New Project
The newly added project too comes under solution explorer.Here we will add code to Set the path varaible value(our new appliacation folder location).In this we have to put the following code

// CODEpublic void SetPathVariable()
{
string[] cmd_args = System.Environment.GetCommandLineArgs();
AppendPathVariable(cmd_args[0]);
}
public void AppendPathVariable(string appPath)
{
try
{

string loc = GetPathOnly(appPath);
// System.Environment.SetEnvironmentVariable(“Path”, loc, EnvironmentVariableTarget.User);
string Value = System.Environment.GetEnvironmentVariable(“Path”, EnvironmentVariableTarget.Machine);
Value = Value + “;” + loc;
System.Environment.SetEnvironmentVariable(“Path”, Value, EnvironmentVariableTarget.Machine);

}
catch (Exception ex)
{
MessageBox.Show(“Omnex CRM found an Error in Setting the Environment variable\n” + ex.ToString());
}
}

// Function to Return the URL exclude the Application(exe) name
public string GetPathOnly(string url)
{
string outputStr = “”;
string ipurl = url;
char[] delimiter = { ‘\\’ };
string[] values = ipurl.Split(delimiter);
for (int i = 0; i < values.Length – 1; i++)
{
if (i == 0)
{
outputStr = values[i];
}
else
{
outputStr = outputStr + “\\” + values[i];
}
}
return outputStr;
}

private void Form1_Load(object sender, EventArgs e)
{
SetPathVariable();
this.Close();
}

//CODE ENDS

This part is over.from the code itself you would have understand what we are doing .
In the Form_Load ,we are calling the method SetPAthVariable().Let us check what is

inside SetPathvaraiable.we are reading the commandline arguments and passing the first
argument to another function called AppendPathVariable.Assume that the first argument
is having the full path to the exe with the executable name.Inside AppendPathVariable,we are caling GetPathOnly() for removing the executable name from the entire path.After that we are fetching the current Path variable then appending the New Path to It.Using the static method SetEnvironmentVariable(),we are setting the newly created path.

Now we have to Pass the Commandline arguments to this Program.For that we will use the custom action feature to our deployment Setup project
(Select the Project View->Editor->Custom Action).

Add Custom Action to Deployment Project

There will be for options such as Install,Commit,Rollback,UnInstall
Select Commit,Right click,Select Add custom action,Select the EXE where i have the code to set the path variable.

Add Custom Action
Click OK
Select the Newly added Exe from the list.Go to its properties,

Set the Installer class property to false.
Set the value of the ARGUMENTS property to

“[OriginalDatabase]<>[TARGETDIR]<>[ComputerName]“

custom Action Properties

Thats all here.
Then just build the Projects-Solution.Get the Latest msi files from the Debug folder of Deployment Setup project

Guys , try this .This was working for me.If you have any queries , Please let me know .Happy to help (with my little knowledge)….

How to use WAMP (Windows-Apache-MySQL-PHP) to setup your PHP development

July 2nd, 2008 Shyju No comments


Last time, i wrote something about Configuring PHP and Apache.But in reality me too did not liked it to do this tedious task.Fortunately one of my friend who was working with PHP for some years told me about WAMP.This guy helped me to get a latest version of WAMP and we installed it ,started working on it. really cool !

WAMP stands for Windows-Apache-MySQL-PHP.I would like to describe WAMP as an Ideal execution environment for developing PHP-MySQl Applications with Apache websercer in Windows platform.

In wamp ,we need not bother about editing the configuration files ,which may be a boring task for some of us,Instead we can do all these(up to an extend) on the installation wizard .Still wamp allow the user to have access to all the config files in one click.You need not go for a search with file name ini.php / httpd.config

You can download WAMP server from here

Once you install wamp,start the wamp server from the start menu.you can see a systray icon in the right bottom side of screen adjacent to the time

WAMP Server SysTrayMenu

Left click on WampServer’s SysTray icon will help us to do the followings:

  • Control Apache and MySQL services
  • Switch online/offline staus
  • install and switch Apache, MySQL and PHP releases
  • Access to MySQL DB front ends like PhpMyAdmin/Sqlite Manager
  • View logs
  • View/Edit configuration settings files..

Now Let us start…………………

When we install our WAMP server in our PC, the installation program automatically create a folder named www inside wamp folder.You can Put your projects in this folder.Take a browser and inthe addressbar type,

http://localhost

WAMP Homepage

Your browser will render a page like the above.There you can find a Heading called “Your Project”.There it will display all the projects we have put under www directory

Wamp ProjectList

This is a snapshot from my PC.30JUNe,Liveprojects,MyBB,MyForum,MyWordpress ,NewFolder are Projects created by me.You can click any one of this iems to navigate to that project.

Above the You projects Title,You can see the Caption “Tools”,under that you can see a list having items “phpinfo”,”phpmyAdmin”,”sqllitemanager”,clicking on the phpinfo leads you to a web page which display all details regarding this installation packages.ie; for example,you can findout which all libraries are supporting our current php version and all.The remaining two,phpmyadmin,sqlitemager are two tools written in php to handle your mysql db.

Thats all Guys…. Try this and revert me if you have any queries .I shall come up with some more stuff soon


Categories: PHP Tags: , , ,