Wednesday, January 28, 2009

How to Use Dos command(WithParameter) through C#

include following file

------------------------------------------------------------------

using System.Diagnostics;

using System.IO;

-------------------------------------------------------------------
On Button Click
------------------------------------------------------------------

ProcessStartInfo myStartInfo = new ProcessStartInfo();

myStartInfo.WorkingDirectory = @"c:\";

myStartInfo.FileName = @"c:\WINDOWS\system32\xcopy.exe";

myStartInfo.Arguments = @"c:\a.bat d:\temp\"; // give proper soucrce and
//destination path

myStartInfo.UseShellExecute = false;

Process myProcess = Process.Start(myStartInfo);

Monday, June 09, 2008

ICallBackHandeler in ASP.NET

Create a Database with following specification:


Code for ICallBackHandeler1.aspx
html xmlns="http://www.w3.org/1999/xhtml" >
head runat="server">
CallBack
/head>
body>
script language="javascript">

function DropDownList1_onChange(sender, eventArgs)
{
var empId =document.getElementById('<%=DropDownList1.ClientID %>').value;
alert(empId);
CallServerSideFunction(empId);
}
function CallbackOnSucceeded(Args)
{
alert(Args);
}
/script>

form id="form1" runat="server">

asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="EMPNO" DataValueField="EMPNO" EnableTheming="false">
Select
/asp:DropDownList>
asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [EMPNO] FROM [EMP]">



/form>

/body>
/html>

Code for ICallBackHandeler1.aspx.CS

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ICallBackHandeler : System.Web.UI.Page, ICallbackEventHandler
{
string IcallBackvalue;
// string empId;
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Attributes.Add("onChange","DropDownList1_onChange();");
RegisterCallBackReference();
SqlDataSource ds = new SqlDataSource();

}
private void RegisterCallBackReference()
{
String callBack = Page.ClientScript.GetCallbackEventReference(this, "args", "CallbackOnSucceeded", "context", true);

String clientFunction = "function CallServerSideFunction(args, context){ " + callBack + "; }";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"Call To Server", clientFunction, true);

}
string ICallbackEventHandler.GetCallbackResult()
{
return IcallBackvalue;
}

void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
string temp;
string name ;
temp = eventArgument.ToString();
if (temp == "HYD0000001")
{
name = "Ashwini Kumar";
}
else if (temp == "HYD0000002")
{
name = "DANODER";
}
else if (temp == "HYD0000003")
{
name = "DEV";
}
else if (temp == "HYD0000004")
{
name = "Ranjit Kumar";
}
else
{
name = "";
}
//IcallBackvalue = "Ashwini";
IcallBackvalue = name;
}
}