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";);