Export DBF and provide download
# Region declare
String mfilepath = mappath ("../datatmp /");
String mtablename = "wyks ";
String mstrconn = @ "provider = Microsoft. jet. oledb.4.0; Data Source = "+ mfilepath + @"/; extended properties = "" dbase iv; HDR = yes ;"";";
System. Data. oledb. oledbconnection moldbconn = new system. Data. oledb. oledbconnection (mstrconn );
If (system. Io. file. exists (mfilepath + "//" + mtablename + ". DBF") = true)
{
System. Io. file. Delete (mfilepath + "//" + mtablename + ". DBF ");
}
# Endregion declare
# Region create a DBF table File
# Region CREATE TABLE
String sqlt = "create table" + mtablename + "(" +
"KSh varchar (18)," +
"Kscj varchar (1)," +
"Kyzk varchar (1)," +
"Yyyd varchar (1)" +
")";
System. Data. oledb. oledbcommand oldbcomm = new system. Data. oledb. oledbcommand (sqlt, moldbconn );
Moldbconn. open ();
Oldbcomm. executenonquery ();
Oldbcomm. Dispose ();
Moldbconn. Close ();
# Endregion CREATE TABLE
# Region Delete tabledate
System. Data. oledb. oledbcommand oldbcommin = new system. Data. oledb. oledbcommand ("delete * from" + mtablename, moldbconn );
Moldbconn. open ();
Oldbcommin. executenonquery ();
Oldbcommin. Dispose ();
Moldbconn. Close ();
# Endregion Delete tabledate
# Endregion create a DBF table File
# Region export data to DBF
String mwhere = "1 = 1 ";
If (this.txt examspoint. Text. length> 0)
{
Mwhere = mwhere + "and examspoint = '" + this.txt examspoint. Text. Trim () + "'";
If (this.txt examinationroom. Text. Trim (). length> 0)
{
Mwhere = mwhere + "and examinationroom in (select examinationroom from t_examinationroom where examinationroomname = '" + this.txt examinationroom. text. trim () + "'and examspoint ='" + this.txt examspoint. text. trim () + "')";
}
}
If (this.txt kshstart. Text. Trim (). length> 0)
{
Mwhere = mwhere + "and KSh> = '" + this.txt kshstart. Text. Trim () + "'";
}
If (this.txt kshend. Text. Trim (). length> 0)
{
Mwhere = mwhere + "and KSh <= '" + this.txt kshend. Text. Trim () + "'";
}
System. Data. dataset mdsoralacademic = new system. Data. dataset ();
Oralexam. entity. t_oralacademic meoralacademic = new oralexam. entity. t_oralacademic ();
Meoralacademic. wherecondition = mwhere;
Oralexam. Data. t_oralacademic.pro_t_oralacademic_selectdynamic (meoralacademic, ref mdsoralacademic, oralexam. basec. globevalues. connstring );
For (INT I = 0; I <mdsoralacademic. Tables [0]. Rows. Count; I ++)
{
Meoralacademic = oralexam. datatoentity. t_oralacademic.getentity (mdsoralacademic, I );
String msqlexport = "insert into" + mtablename + "(Ksh, kscj, kyzk, yyyd )";
Msqlexport = msqlexport + "select ";
Msqlexport = msqlexport + "'" + meoralacademic. ksh + "' As ksh ,";
Msqlexport = msqlexport + "'" + meoralacademic. academiccode + "' As kscj ,";
Msqlexport = msqlexport + "'" + meoralacademic. oralstatus. tostring () + "' As kyzk ,";
Msqlexport = msqlexport + "'" + meoralacademic. tonestatus. tostring () + "' As yyyd ";
System. Data. oledb. oledbcommand oldbcomminsert = new system. Data. oledb. oledbcommand (msqlexport, moldbconn );
Moldbconn. open ();
Oldbcomminsert. executenonquery ();
Oldbcomminsert. Dispose ();
Moldbconn. Close ();
}
# Endregion export data to DBF
# Region download
System. io. filestream FS = new system. io. filestream (mfilepath + "//" + mtablename + ". DBF ", system. io. filemode. open, system. io. fileaccess. read );
Byte [] B = new byte [fs. Length];
FS. Read (B, 0, B. Length );
FS. Flush ();
FS. Close ();
// System. Io. file. Delete (savepdfpath );
Response. Clear ();
Response. clearheaders ();
Response. Clear ();
Response. clearheaders ();
Response. Buffer = false;
Response. contenttype = "application/octet-stream"; // contenttype;
Response. appendheader ("content-disposition", "attachment; filename =" + httputility. urlencode (mfilepath + "//" + mtablename + ". DBF ", system. text. encoding. utf8 ));
Response. appendheader ("Content-Length", B. length. tostring ());
FS. Close ();
FS. Close ();
If (B. length> 0)
{
Response. outputstream. Write (B, 0, B. Length );
}
Response. Flush ();
Response. End ();
# Download endregion
Others:
From: http://www.cnblogs.com/jyshi/