Dos command to close and open port

Author posted by Jitendra on Posted on under category Categories Tech Tips and tagged as Tags , with 2 Comments on Dos command to close and open port

Dos command to close and open port in Windows XP, Windows 7 and Windows Server

1)Type  netstat -a -o -n in command prompt.

Netstat command in DOS
Netstat command in DOS

2) find the PID number for that port number (as shown in above image).
3) goto task manager and end process the corresponding PID number.

Close Open Port from Task manager in Windows xp
Close Open Port from Task manager in Windows xp

If  PID is not visible in task manager then goto View->Select Column and select PID column.

How to Install java on Ubuntu 10 and Ubuntu 11

Author posted by Jitendra on Posted on under category Categories JAVA, Linux and tagged as Tags , , with Leave a comment on How to Install java on Ubuntu 10 and Ubuntu 11
Run below command on the terminal of ubuntu to install the JAVA.
Ubuntu 10 :
	$ sudo add-apt-repository "deb http://archive.canonical.com/lucid partner"
	$ sudo apt-get update
	$ sudo apt-get install sun-java6-jdk
	$ sudo apt-get install sun-java6-jre

Ubuntu 11:

sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-jre
sudo update-alternatives --config java

Get Mouse Position in JavaScript for all browsers

Author posted by Jitendra on Posted on under category Categories Tech Tips and tagged as Tags with Leave a comment on Get Mouse Position in JavaScript for all browsers

 

Get Mouse Movement in Javascript
Get Mouse Movement in Javascript
function mouseXPos(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
return evt.clientX + (document.documentElement.scrollLeft ?
document.documentElement.scrollLeft :
document.body.scrollLeft);
else return null;
}

function mouseYPos(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
return evt.clientY + (document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body.scrollTop);
else return null;
}

To use above function, just pass the mouse event.

Live Demo

Why Style.left does not work in Firefox, chrome and safari ?

Author posted by Jitendra on Posted on under category Categories HTML and tagged as Tags , with 3 Comments on Why Style.left does not work in Firefox, chrome and safari ?

During working on one of my project, i found that style.left does not work with Mozilla, chrome and safari but nicely works on internet explorer.

The code was :

var docStyle = document.getElementById("divAddPartnerAndProjectEntities").style;
docStyle.top = e.clientY;
docStyle.left = e.clientX-5;
docStyle .style.display = "";
And the simple solution is, append “px” at the end to work with other browsers.
and final code is:
var docStyle = document.getElementById("divAddPartnerAndProjectEntities").style;
docStyle.top = e.clientY+"px";
docStyle.left = e.clientX-5+"px";
docStyle .style.display = "";

Very Simple right ? 🙂

DataGrid Sorting and Paging Example – Part 2

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags , with Leave a comment on DataGrid Sorting and Paging Example – Part 2

For Part 1, visit This URL http://JitendraZaa.com/blog/?p=191

In this part, i will show that how to Sort the Datagrid Component of ASP.NET.

To sort Datagrid, we will need DataView and then assign Dataview as datasource to our Grid control.

We will need to change our code of Part 1.

Previously, we used DataSet as a Datasource. This time we will use DataTable and get the DataView from DataTable using below line.

DataView dv = dt.DefaultView; //Where dt id DataTable

So we have created a function, which will return the DataTable as shown below:

private DataTable GetTableFromDataBase()
{
SqlConnection con = null;
SqlDataAdapter adp = null;
DataTable dt = new DataTable();
try
{
con = new SqlConnection(conString);
con.Open();
adp = new SqlDataAdapter("Select * from Employee",con);
adp.Fill(dt);
return dt;
}
catch (CustomException ex)
{
ex.logException();
}finally{
con.Close();
}
return null;
}

we will need to create the function on Sortcommand of the DataGrid.

The format for sorting the grid is like:

SortExpression+”asc”

OR

SortExpression+”desc”

Below is the code snap used for the sorting:

protected void grdEmp_Sort(object source, DataGridSortCommandEventArgs e)
{
DataTable dt = GetTableFromDataBase();
DataView dv = dt.DefaultView;
string dir = string.Empty;
if (e.SortExpression.Length > 0)
{
if (Session["OldSortDir"] == null)
{
Session["OldSortDir"] = e.SortExpression;
}
else
{
string oldSortExp = Session["OldSortDir"].ToString();
if (oldSortExp == "asc")
{
dir = "desc";
Session["OldSortDir"] = "desc";
}
else
{
dir = "asc";
Session["OldSortDir"] = "asc";
}
}
dv.Sort = e.SortExpression+"  "+dir;
}
grdEmp.DataSource = dv;
grdEmp.DataBind();
}

The code for the Pagination is written below. Consider Page Size as 3.

protected void grdEmp_Paging(object source,DataGridPageChangedEventArgs p)
{
grdEmp.CurrentPageIndex = p.NewPageIndex;
BindTable();
}

Download Source code

DataGrid Example – Part 1

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags , with 1 Comment on DataGrid Example – Part 1

For the basics of DataGrid please refer this post: http://JitendraZaa.com/blog/?p=188

In this example, i will explain the basics of DataGrid control like Theming, Databinding etc.

We will start our example with creating the SQL Express database of Employee which will contain the following fields : Id, FName, LName, Email.

Now create a stored procedure to insert the data into Table.

CREATE PROCEDURE dbo.AddEmployee
@FName varchar(50),
@LName varchar(50),
@Email varchar(50)
AS
INSERT INTO Employee (FName,LName,Email) values (@FName,@LName,@Email)

In ASPX page, write the code to input the Employee information.

First Name : <asp:TextBox ID="txtFName" runat="server"/><br />
Last Name :<asp:TextBox ID="txtLName" runat="server"/><br />
Email :<asp:TextBox ID="txtEmail"; runat="server"/><br />
<asp:Button ID="btnSubmit" Text="Add Record" runat="server" OnClick="btnSubmit_Click"/>

Go to the property of Employee.mdf and select connection string as shown in below image.

On the click event of the button write below function:

string conString = @"Data Source=.SQLEXPRESS;AttachDbFilename=""|DataDirectory|Employee.mdf"";Integrated Security=True;User Instance=True";
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = null;
SqlCommand cmd = null;
try {
con = new SqlConnection(conString);
     con.Open();
     cmd = new SqlCommand("AddEmployee", con);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@FName", txtFName.Text);
     cmd.Parameters.AddWithValue("@LName", txtLName.Text);
     cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
     cmd.ExecuteNonQuery();
     showConfirmationMessage();
}
catch (CustomException ex) {
ex.logException();
}finally{
    con.Close();
}
}
 private void showConfirmationMessage()
{
      ClientScriptManager csMngr = Page.ClientScript;
      csMngr.RegisterStartupScript(Page.GetType(), "Success", "alert('Record Added succesfully');", true);
}

ASPX Code for data grid

<asp:DataGrid ID="grdEmp" runat="server">
<HeaderStyle CssClass="Header" />
<AlternatingItemStyle CssClass="AlternateItemStyle" />
</asp:DataGrid>

Write below code to bind the data into DataGrid.

private void bindData()
{
SqlConnection con = null;
SqlDataAdapter adp = null;
try
{
con = new SqlConnection(conString);
con.Open();
adp = new SqlDataAdapter("Select * from Employee",con);
DataSet ds = new DataSet();
adp.Fill(ds);
grdEmp.DataSource = ds;
grdEmp.DataBind();
}
catch (CustomException ex)
{
ex.logException();
}finally{
con.Close();
}
}

Final output:

Download Code

ASP.NET DataGrid basic questions

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags , with 2 Comments on ASP.NET DataGrid basic questions
  1. What is datagrid? The DataGrid Web server control is a powerful tool for displaying information from a data source. It is easy to use; you can display editable data in a professional-looking grid by setting only a few properties. At the same time, the grid has a sophisticated object model that provides you with great flexibility in how you display the data.
  2. What’s the difference between the System.Web.UI.WebControls.DataGrid and System.Windows.Forms.DataGrid? The Web UI control does not inherently support master-detail data structures. As with other Web server controls, it does not support two-way data binding. If you want to update data, you must write code to do this yourself. You can only edit one row at a time. It does not inherently support sorting, although it raises events you can handle in order to sort the grid contents. You can bind the Web Forms DataGrid to any object that supports the IEnumerable interface. The Web Forms DataGrid control supports paging. It is easy to customize the appearance and layout of the Web Forms DataGrid control as compared to the Windows Forms one.
  3. How do you customize the column content inside the datagrid? If you want to customize the content of a column, make the column a template column. Template columns work like item templates in the DataList or Repeater control, except that you are defining the layout of a column rather than a row.
  4. How do you apply specific formatting to the data inside the cells? You cannot specify formatting for columns generated when the grid’s AutoGenerateColumns property is set to true, only for bound or template columns. To format, set the column’s DataFormatString property to a string-formatting expression suitable for the data type of the data you are formatting.
  5. How do you display an editable drop-down list? Displaying a drop-down list requires a template column in the grid. Typically, the ItemTemplate contains a control such as a data-bound Label control to show the current value of a field in the record. You then add a drop-down list to the EditItemTemplate. In Visual Studio, you can add a template column in the Property builder for the grid, and then use standard template editing to remove the default TextBox control from the EditItemTemplate and drag a DropDownList control into it instead. Alternatively, you can add the template column in HTML view. After you have created the template column with the drop-down list in it, there are two tasks. The first is to populate the list. The second is to preselect the appropriate item in the list “” for example, if a book’s genre is set to “fiction,” when the drop-down list displays, you often want “fiction” to be preselected.
  6. How do you check whether the row data has been changed? The definitive way to determine whether a row has been dirtied is to handle the changed event for the controls in a row. For example, if your grid row contains a TextBox control, you can respond to the control’s TextChanged event. Similarly, for check boxes, you can respond to a CheckedChanged event. In the handler for these events, you maintain a list of the rows to be updated. Generally, the best strategy is to track the primary keys of the affected rows. For example, you can maintain an ArrayList object that contains the primary keys of the rows to update.

You can find more questions on Datagrid at http://msdn.microsoft.com/en-us/library/Aa289519

Problems with parallel RFC servers in SAP

Author posted by Jitendra on Posted on under category Categories SAP and tagged as Tags , with 2 Comments on Problems with parallel RFC servers in SAP

 

Generally, the transaction RZ12  is used to create and edit RFC server groups for parallel execution of RFC enabled ABAP procedures and functions.  Using these parallel RFCs, we can reduce the overall execution time of long running jobs. 

Below are rare facts about the configuration of RFC servers in RZ12:

1. While configuring the resources which will be assigned to RFC servser groups; we will find that the “Determination of Resources” section allows to enter the preferences for the amount of system resources that will be allocated to the group.  Here, the problem is, the data entered  for these parameters is not RFC server group specific. Its actually application group wide, just like all the other profile parameters.  So, if we edit  RFC server group assignment row  and change its any field value, we change its corresponding application servers profile parameter and this change affects all RFCs running in the application server. This can be verified by opening any other RFC  server group.

 

2.  As we know the profile parameter  “rdisp/rfc_check”  enables the dispatcher check for asynchronous RFCs (checks whether the sufficient Dialogue work processes are available for processing the asynchronous RFC calls) and its default value is 2 but if we change it to 3 then the both Synchronous and Asychronous RFCs can be monitored. I would suggest to take a view of available Dialogue work processes and the documentation changing this value.

3.  If the parallel RFCs are being used to generate the periodic replacement list using transaction code EG88 then it calls the function EGTUR. In such a case, define the RFC group with name EGTUR and activate the same.

Handlers in ASP.NET

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags with 2 Comments on Handlers in ASP.NET

HTTP Handlers is a new technique presented in ASP.NET that was not present in the “Classic ASP”. HTTP Handlers are components that implement the System.Web.IHttpHandler interface. Unlike ASP.NET pages Handlers dont have HTML-markup file, no events and other supporting. All they have is a code-file (written in any .NET-compatible language) that writes some data to the server HTTP response.

ASP.NET handlers have “.ashx” file extension (unlike pages, that have “.aspx” file extension).

Handlers are considered to be more lightweight object than pages. That’s why they are used to serve dynamically-generated images, on-the-fly generated PDF-files and similar content to the web-browser.

One such scenario which may arise in any product is that if  I owe a site and I want to restrict the user from downloading a file if he/she is not logged in. But if the user (not logged) is allowed to see the url of the downloading file then he can just copy the url and paste it in another tab and he can easily download the file from there, i.e. my protection mechanism failed. Now here comes the use of handlers.

The handlers will restrict the user to even view  the url of the file to be downloaded unless he is logged in.

How to create the Handlers in ASP.NET in Visual Studio 8.0.

First step is to create new project-

Step 1) Open Visual Studio an Goto – File Menu ->New -> Project.

Step 1
Step 1

Step 2) Now new window will open then select  Web -> ASP.NET Web Appliction. Then rename it and click ok.

Step 2
Step 2


Step 3) Now we have to add the Handler (Don’t call it the page, its all different thing) Follow the steps to include the handler in the current project.

First Right Click on the Solution Explorer -> Add -> New Item ->

Step 3

Step 4) Then new window will be displayed. Then select the Generic Handler and rename it then click on Add–>

 

ASP.Net Handlers
Step 4

Step 5) Now open the Default.asp page in Design view and design the form as required using Button Tool from toolbox.

Step 5
Step 5

Step 6) Then write the following code on the click event of both the buttons in Default.aspx.cs page (Just double click on the buttons and it will automatically generate the block in source page)

protected void btnWoutSecurity0_Click(object sender, EventArgs e)
{
     Response.Redirect("LinkSecurty.ashx?isSecure = 1");
}
protected void btnWoutSecurity_Click(object sender, EventArgs e)
{
      Response.Redirect("LinkSecurty.ashx");
}
Step 7) Now open the Handler which we have created earlier i.e. LinkSecurity.aspx.cs  and write the following code–
public class LinkSecurity : IHttpHandler
{
     public void ProcessRequest(HttpContext context)
     {
        if (context.Request["isSecure"] == null)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("You are not Logged In.... Please Login to access this page...");
        }else
        {
            context.Response.ContentType = "image/png";
            context.Response.WriteFile("imageName.png")
        }
      }
      public bool IsReusable
      {   get{return false;}
      }
}

Upload Files in ASP.NET at Production server

Author posted by Jitendra on Posted on under category Categories ASP.NET and tagged as Tags , , , with Leave a comment on Upload Files in ASP.NET at Production server

In this article, i am going to demonstrate that how to upload the file in ASP.NET production server.

Most of the case, a developer created a code to upload the file and test it on his local machine. program runs smoothly, but as he forward the same code on production. He stuck in the file permission error as on the local he has the full permission whereas on development its not the case.

So i decided to write this tutorial for the beginners which will demonstrate lots of ASP.NET features.

First we need to create a folder in Server and share it with ASP.NET web server as described.

Right click on folder, select Web sharing tab and select the radio button “Share this folder”. One  window appear, give it alias name which will be used in coding.

After this, open Run box and type “inetmgr“. you will see that your web shared folder appears in the IIS.

Right click on folders property. one window will opened.

Select “Directory Security” tab then click on “Edit” button and then check “Anonymous access”. And because of this setting any body can access or download that file.

Now we are ready, to create a sample application which will demonstrate that how to upload the file and use it.

Create ASP.NET project in Visual Studio. Create a webpage with fileupload, hyperlink and button control.

<form id="form1" runat="server">
<asp:FileUpload ID="uploadFile" runat="server" /><br />
<asp:HyperLink ID="hypLink" runat="server" Visible="false" Target="_blank"></asp:HyperLink><br />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="btnUpload_Click" />
</form>

In web.config add two keys.  One for actual folder location in which we are going to upload the files and other its alias name. we can also hard code that, but its good practice to make it configurable at any time because in near future we may want to change the location.


<appSettings>

<add key="DemoAttachment" value="D:ShareDemoShare"></add>

<add key="DemoAttachmentVirtualPath" value="http://localhost/DemoShare/"></add>

</appSettings>

In DemoAttachmentVirtualPath key, value should like “http://machinename/” + Alias folder name.

On click event of button, write below code:

string strPath = ConfigurationManager.AppSettings["DemoAttachment"];
uploadFile.SaveAs(strPath + System.IO.Path.GetFileName(uploadFile.FileName));
hypLink.Visible = true;
string VirtualPath = ConfigurationManager.AppSettings["DemoAttachmentVirtualPath"];
hypLink.Text = System.IO.Path.GetFileName(uploadFile.FileName);
hypLink.NavigateUrl = VirtualPath + uploadFile.FileName;
string strPath = ConfigurationManager.AppSettings["DemoAttachment"];

uploadFile.SaveAs(strPath + System.IO.Path.GetFileName(uploadFile.FileName));
hypLink.Visible = true;
string VirtualPath = ConfigurationManager.AppSettings["DemoAttachmentVirtualPath"];

hypLink.Text = System.IO.Path.GetFileName(uploadFile.FileName);

hypLink.NavigateUrl = VirtualPath + uploadFile.FileName;

The output will look like:

Download Source code

For the file size limitation, please visit this article : http://JitendraZaa.com/blog/?p=125