HTML

ksdh


hello



hello

he,llo





LHLSAFHSDHFLHSD






tESsting sdlaflsdflsdfhl lsdjfjsdf

testingfeb03






testing






testing google docs






testing
<>

Open EXE Using Javascript

Labels:

<html>
<head>
<script language="javascript">
function loadexe()
{
alert('invoke');
w = new ActiveXObject("WScript.Shell");
w.run('notepad.exe');
return true;
}
</script>
</head>
<body onload=loadexe()>
</body>
</html>

CONVERT IMAGE TO BYTE USING ASP.NET

Labels: ,

Namespaces :-

System.Drawing;

Coding :-

byte[] bytArray;
Bitmap bImg = new Bitmap(Server.MapPath(path));
ImageConverter imgCon = new ImageConverter();
bytArray = (byte[])imgCon.ConvertTo(bImg , typeof(byte[]));

Upload the File in ASP.NET

Labels:

In this example we browse a file from our pc and upload that file to some other loaction in our pc.

Default.aspx

\\Place a file type textbox and a button




<input type=file id=File1 name=File1 runat="server">
<input type="submit" id="Submit1" value="Upload" runat="server" name="Submit1">

Defalut.aspx.cs

if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength > 0 ) )
{
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Data") + "\\" + fn;\\Create Data Folder within the Location u Specified
\\File will be Uploaded to the Specified Location
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch ( Exception ex )
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}

Copy Data From Excel to GridView

Labels:

We have to create a excel as a database.

Step 1 : Open Excel sheet and enter data's

Step 2 : Select the data's which u want.

Step 3 : Click Insert tab->Name->Define




Step 4 : Give the name for the selected data's




pgeExcel.cs

Now we display the excel database in a gridview which we created.

OleDbDataAdapter da;
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=f:/Book1.xls;Extended Properties=Excel 8.0;");
con.open();
da = new OleDbDataAdapter("select * from emp", con);//emp is the name given in excel sheet
DataSet ds=new DataSet();
da.Fill(ds,"emp");
GridView1.DataSource=ds;
GridView1.DataBind();

Connection String For ASP.NET using Oracle

Labels: ,

// Data Provider for OLE DB
using System.Data.OleDb

OleDbConnection oracleConn = new OleDbConnection("Provider= \"OraOLEDB.Oracle.1\";User ID=scott;Password=tiger;Data Source=yourSource; Extended Properties="";Persist Security Info=False";);

//Data Provider for ODBC
using System.Data.Odbc

OdbcConnection oracleConn = new OdbcConnection("DSN=odbcName ;UID=scott;PWD=tiger;DRIVER={Microsoft ODBC for Oracle};
SERVER=oracleServerNameOr IPAddress;";);

//
Data Provider for Oracle Client
using System.Data.OracleClient

OracleConnection oracleConn = new OracleConnection("user id=scott;
data source=oracleSN;password=tiger";);

Fill DropDownList with first Item as Select/All

Labels:

when we want the first item of dropdownlist to be user defined which is binded from the database,we have to insert a new row in the dropdownlist at first postion and give the DataTextField as our requirement.

Coding :

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\\PrjAspnet\\test1\\db1.mdb");
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
OleDbDataAdapter da = new OleDbDataAdapter("select empid,empname from emp", con);
DataTable dt = new DataTable();
da.Fill(dt); // fill dropdown from database
dr = dt.NewRow();
dr[0] = "0"; //DataValueField
dr[1] = "-------- Select --------"; //or dr[1] = "All" // DataTextField
dt.Rows.InsertAt(dr, 0); // give the postion where you want item to be
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "empname";
DropDownList1.DataValueField = "empid";
DropDownList1.DataBind();
}

Or

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\\PrjAspnet\\test1\\db1.mdb");
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
OleDbDataAdapter da = new OleDbDataAdapter("select empid,empname from emp", con);
DataTable dt = new DataTable();
da.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "empname";
DropDownList1.DataValueField = "empid";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "--Select--");
DropDownList1.Items.FindByText("--Select--").Value = "0";
}

Script to Make TextBox to Enter Only NUMBER

Labels:

<script language=javascript>
function NumberOnly()
{
var keyCode = event.keyCode;

if(keyCode > 47 && keyCode < 58)
{
return true;
}
else
{
return false;
}
}
</script>

<asp:TextBox ID="txt" runat="server" onkeypress="return NumberOnly()"></asp:TextBox>

Place the Script in the keyPress Event of the textbox to see the result.

To write a Script in server side in Asp.net

Labels: ,

Syntax :

ScriptManager.RegisterStartupScript(Control control,type type,string Key,string Script,bool addScriptTags)

Example:

string s = "alert('Hello')";

ScriptManager.RegisterStartupScript(this, this.GetType(), "Hello", s, true);

If you give the script tag in the string s then give addScriptTags to false.

ScriptManager is a class inside System.Web.UI

As a result a alert box with 'hello' pops up, where you place this line.

Authorization

Labels:

Authorization is to determine whether an identity should be granted the requested type of access to a given resource.

users: Assign a list of users to be granted or denied access

Roles: Assign a list of roles to be granted or denied access

<authorization>
<allow users="Don , Jim" roles="Admins" /> //Allow only two user Don,Jim

<deny users="*" /> //Restrict all other user

</authorization>

//Allow All the user to access

<authorization>
<allow users="*" />
</authorization>

* Refers to all identities
? Refers to the anonymous identity




SEARCH ALL FLOPPY,CD AND HARD DISK DRIVES

Labels:

//search all floppy,cd and hard disk drives available in our PC
//its varies from system to system


for(char Ch='A';Ch<='Z';Ch++) { string Dir = Ch + @":\"; if (Directory.Exists(Dir)) {
disksListBox.Items.Add( Ch+ @":" ); //Add into ListBox
}
}

COPY AND PASTE THE DATA USING CLIPBOARD

Labels:

//copy the data using Clipboard

Clipboard.SetDataObject(textBox1.SelectedText,true);

//paste the data using Clipboard

IDataObject iData = Clipboard.GetDataObject();

//Determine whether the data is in a format you can use.

if(iData.GetDataPresent(DataFormats.Text))
{
textBox1.SelectedText =(String)iData.GetData(DataFormats.Text); //display it in a text box.
}

GET THE USER NAME IN C# FOR NT AUTHENTICATION

Labels:

//Declare the Header File

using System.Security.Principal;
string a;

a=System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

//Above Statement,opens us up to more than just the current user.

MessageBox.Show(a.ToString());

TO EXECUTE THE .exe FILE IN RUNTIME

Labels:

System.Diagnostics.Process.Start("calc");
System.Diagnostics.Process.Start("f:\\start.exe");

WRITE THE DATA INTO FILE

Labels:

using(StreamWriter sr=new StreamWriter("F:\\out.txt"))
{
sw.write("Have a nice day");
Response.write("saved");
}

READ THE DATA FROM FILE

Labels:

using(StreamReader sr=new StreamReader("h:\\appl.txt"))
{
while(sr.ReadLine()!=null)
{
string s;
s=sr.ReadLine();
ListBox1.Items.Add(s);
}
}