Wednesday, 8 December 2010

how to configure DHCP in windows server 2003?

The Dynamic Host Configuration Protocol (DHCP) is an auto configuration protocol used on IP networks. Computers that are connected to IP networks must be configured before they can communicate with other computers on the network. DHCP allows a computer to be configured automatically, eliminating the need for intervention by a network administrator. It also provides a central database for keeping track of computers that have been connected to the network. This prevents two computers from accidentally being configured with the same IP address.
Here is some links for configuring DHCP in the local network:
1. http://www.windowsreference.com/windows-server-2003/install-and-configure-dhcp-server-in-win-server-2003-step-by-step-guide/


2. http://www.windowsnetworking.com/articles_tutorials/DHCP_Server_Windows_2003.html

Tuesday, 23 November 2010

How to get the path of AppData for an application?

Often in windows OS, a separate directory is created for an application for a user for saving user-specific information and user has the administrative right on that folder. Recently, I was working on a project with winxp platform. While client was testing the same software on win 7 , he found that the application failed to create the or modify a file in the system directory where the application was loaded. So, then the concept of Appdata came and I implemented the solution using the link provided by client.
Here is the link
http://stackoverflow.com/questions/946420/allow-access-permission-to-write-in-program-files-of-windows-7
And here is my code for getting the AppData folder

XmlDocument xmldoc = new XmlDocument();

string xmlfilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

//loading the file
xmldoc.Load(xmlfilepath + "/" + "enstatics.xml");
//returning the xmldoc
return xmldoc;

DNS setup in Ubuntu Linux

Recently, I assigned a project of setting mail server as network lab project for fourth year 1st term students. Anyway, no group came out with what I expected. Anyway, the first thing is here is needed is a successful DNS server.
Here is a post I created for DNS setup in Ubuntu Linux with BIND software.
DNS setup in ubuntu
Here is the link http://cseku.technopeople.net/setting-up-dns-linux.aspx

Working with xml file in C#

Well, Currently I am working with a project called webcam desktop application which mainly captures snapshot and video from the webcam. Before, starting the project, I had very little concept about how to do that and before me, an experienced developer worked on it. Anyway, my task was to fix the bugs. Whenever, I started bug-fixing, I found that previous coder used Appsetting to store information, which polls some static information from the system and nothing customization saved at run time, can be restored in the next run of the system. So, I came to plan to save the information in the xml file. Here I am going to show several things like


1. Creating xml file dynamically
2. Modifying the xml file
3. Reading from the xml file.

Creating XML file dynamically

//code for creating and saving default config
public void create_config_xml_file()
{
try {
//xml doc
XmlDocument xmldoc = new XmlDocument();

//xml declaration
XmlDeclaration xmldeclaration = xmldoc.CreateXmlDeclaration("1.0", "utf-8", null);

//create root element
XmlElement rootNode = xmldoc.CreateElement("myconfigdata");
xmldoc.InsertBefore(xmldeclaration, xmldoc.DocumentElement);
xmldoc.AppendChild(rootNode);

//adding more children to the root node

//imageformatindex
XmlElement ifiElement = xmldoc.CreateElement("imageformatindex");
ifiElement.InnerText = "1";
rootNode.AppendChild(ifiElement);

//currentdirectory
XmlElement currDirElement = xmldoc.CreateElement("currentdirectory");
currDirElement.InnerText = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
rootNode.AppendChild(currDirElement);

//fileprefix
XmlElement fpElement = xmldoc.CreateElement("fileprefix");
fpElement.InnerText = "ISeeStand";
rootNode.AppendChild(fpElement);

//filesuffixid
XmlElement fsElement = xmldoc.CreateElement("filesuffixid");
fsElement.InnerText = "2";
rootNode.AppendChild(fsElement);

//sequential
XmlElement seqElement = xmldoc.CreateElement("sequential");
seqElement.InnerText = "0";
rootNode.AppendChild(seqElement);

//sequentialvid
XmlElement seqVidElement = xmldoc.CreateElement("sequentialvid");
seqVidElement.InnerText = "0";
rootNode.AppendChild(seqVidElement);

//videncoder
XmlElement videncElement = xmldoc.CreateElement("videncoder");
videncElement.InnerText = "WMVideo9 Encoder DMO";
rootNode.AppendChild(videncElement);

//framesize
XmlElement fsizeElement = xmldoc.CreateElement("framesize");
fsizeElement.InnerText = "800 x 600 @5.00 fps";
rootNode.AppendChild(fsizeElement);

//framerate
XmlElement frateElement = xmldoc.CreateElement("framerate");
frateElement.InnerText = "5.00 fps";
rootNode.AppendChild(frateElement);

//getting appdata folder
string app_path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

//saving that document
xmldoc.Save(app_path+"/"+"enstatics.xml");

}
catch (Exception exc) {
MessageBox.Show("Failed to create the xml configuration file."+exc.Message);
}
}

From the above code, we can see how to use XMLDocument object and XmlNode for creating a XML file.

Modifying the XML file

The following code saves some info into the xml file accessing a particular XmlNode


//saving the image format index to the xml file
try {
XmlDocument xmldoc = MyStaticMgr.loadMyXMLDoc();
XmlNode formatIndexNode = xmldoc.GetElementsByTagName("imageformatindex")[0];
//setting the preferences to the xml node
formatIndexNode.InnerText = (ImageformatComboBox.SelectedIndex + 1).ToString();
//now saving the xml file
int result=MyStaticMgr.saveMyXMLDoc(xmldoc);
}
catch (Exception exc) {
MessageBox.Show("Failed to save the preferences"+exc.Message);
}

Reading from XML file

The following code will demonstrate how to access a particular node of the xml file for a particular information

//making a default choice
try {

XmlDocument xmldoc = MyStaticMgr.loadMyXMLDoc();
XmlNode formatIndexNode = xmldoc.GetElementsByTagName("imageformatindex")[0];
int format_index = int.Parse(formatIndexNode.InnerText);
//now setting that index to the combobox
ImageformatComboBox.SelectedIndex = format_index - 1;
}
catch (Exception exc) {
string messageBoxText = exc.Message;
string caption = "Exception Occurred";
MessageBox.Show(messageBoxText, caption);
}


From the above codes we found a particular section like this

XmlDocument xmldoc = MyStaticMgr.loadMyXMLDoc();

and

//now saving the xml file
int result=MyStaticMgr.saveMyXMLDoc(xmldoc);

Actually, MyStaticMgr is a static class which handles the basic operation like opening an xml document and returning the document object or saving the xmldocument object. Here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace ISeeStand
{
public static class MyStaticMgr
{

//code for loading the xml document
public static XmlDocument loadMyXMLDoc()
{
XmlDocument xmldoc = new XmlDocument();
string xmlfilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//loading the file
xmldoc.Load(xmlfilepath + "/" + "enstatics.xml");
//returning the xmldoc
return xmldoc;

}

//code for saving to the xml file
public static int saveMyXMLDoc(XmlDocument xmldoc)
{
int saved = 0;
try {
string xmlfilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//loading the file
xmldoc.Save(xmlfilepath + "/" + "enstatics.xml");
//yes the file is saved
saved = 1;
}
catch (Exception exc) {
string messageBoxText = exc.Message;
string caption = "Exception Occurred";
MessageBox.Show(messageBoxText, caption);
}

//returning the result
return saved;

}



}
}

Sunday, 29 August 2010

Handling event from Context Menu strip after a Right Click

Recently I deal with this problems for 1-1.5 hours. Anyway, lastly I figured it out how to perform this operations: Here are the steps. We need three controls for this

  • Windows form

  • ListView Control

  • ContextMenu Strip


Step-1:Loading listview items::



The following code loads the items to listview control.

protected void load_courses()
{

//code for loading the courses
try {
OleDbConnection conn = new OleDbConnection(StaticData.connection_string);
conn.Open();
string select_courses = "select * from Course";
OleDbDataAdapter oda = new OleDbDataAdapter(select_courses, conn);
DataTable dt = new DataTable();
oda.Fill(dt);

//databinding to the listview
TestlistView.Items.Clear();
for(int i=0;i < dt.Rows.Count;i++)
{
DataRow row = dt.Rows[i];
ListViewItem lvi = new ListViewItem(row["CourseNo"].ToString());
lvi.SubItems.Add(row["CourseID"].ToString());
lvi.SubItems.Add(row["Credit"].ToString());
TestlistView.Items.Add(lvi);
}


}
catch (Exception exc) { }
}



private void Form1_Load(object sender, EventArgs e)
{

//code for loading the courses
load_courses();

}



Step-2:Handling the right click event on listview items:



private void TestlistView_MouseClick(object sender, MouseEventArgs e)
{

if (e.Button == MouseButtons.Right)
{
Point pt = TestlistView.PointToScreen(e.Location);
contextMenuStrip1.Show(pt);
}


}


Step-3:Handling context menu strip event



private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "Upload")
{
MessageBox.Show("Upload started for:" + TestlistView.SelectedItems[0].Text);
}
}




Thats how we can use right click event to show a context menu strip and handle menu strip click events.
thanks. Masud(29-08-2010)

Tuesday, 20 April 2010

Using image map and popupcontrol extender

In interactive map client provided me a jquery library which is called zoom map and he instructed to work according to that but I found some problem in work with multiple version of jquery. For example jquery-min-1.3.2 does not support the coexistence with jquery-1.4.2.js. Anyway, I am going to describe here, how to use image map and popupcontrolextender. To perform this we need to follow these steps:

Step-1: We have to register the AjaxControlToolkit for using its control which we are calling here PopupControlExtender.

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


Step-2:
Consider an image containing lots of hot spot and when there is a click on that hot spot certain popup-winow will show up. So, here is the code for image and map.

< img id="homeimg" src="maps/map-bg-w-dots.jpg" style="border-width:0px" runat="server" alt="" usemap="#homemap" / >
< map name="homemap" id="homemap">
< area id="hole1area" runat="server" target="_self" onclick="showdetails(1)" shape="circle" style="cursnor:pointer" alt="" coords="314,178,7"/>
< area id="hole2area" runat="server" target="_self" onclick="showdetails(2)" shape="circle" style="cursor:pointer" alt="" coords="285,56,7"/>
< /map>



Here, onclick="showdetails(1)" can be used to populate data from some xml file relevant to hole1area if needed. As for example I have done in
my map project

Step-3:
Now we need the popup control extender that will generate a popup. So, here is the code below:

< asp:ScriptManager runat="server">< /asp:ScriptManager>
< cc1:PopupControlExtender runat="server" ID="MyPopupExtender1" OffsetX="550" OffsetY="300" PopupControlID="popupwindow1" TargetControlID="hole1area">
< /cc1:PopupControlExtender>
< cc1:PopupControlExtender runat="server" ID="MyPopupExtender2" OffsetX="550" OffsetY="300" PopupControlID="popupwindow2" TargetControlID="hole2area">
< /cc1:PopupControlExtender>


< div id='popupwindow1'>
Description for hole1...............
< /div>
< div id='popupwindow2'>
Description for hole2................
< /div>



Here, several thing to notice:
TargetControlID= the control which will be clicked on.
PopupControlID= the control which will be shown as popup.
OffsetX= the X position where popup will be shown
OffsetY= the Y position where popup will be shown.

So, this is the simplest way to use image map and popupcontrolextender. And whenever I started working client become excited as I was not using his solution but finally I ended up with good solution and he was quite satisfied. So, this project was one of the challenging task to me.

thanks. Masud.