导出DBF,并且提供下载 .

原文:导出DBF,并且提供下载 .

导出DBF,并且提供下载

                 #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 创建DBF表文件

                #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 创建DBF表文件

                #region 导出数据到DBF

                string mWhere = " 1=1";
                if (this.txtExamsPoint.Text.Length > 0)
                {
                    mWhere = mWhere + " And ExamsPoint = '" + this.txtExamsPoint.Text.Trim() + "'";

                    if (this.txtExaminationRoom.Text.Trim().Length > 0)
                    {
                        mWhere = mWhere + " And ExaminationRoom In(Select ExaminationRoom From T_ExaminationRoom Where ExaminationRoomName = '" + this.txtExaminationRoom.Text.Trim() + "' And ExamsPoint = '" + this.txtExamsPoint.Text.Trim() + "')";
                    }
                }
                if (this.txtKSHStart.Text.Trim().Length > 0)
                {
                    mWhere = mWhere + " And KSH >= '" + this.txtKSHStart.Text.Trim() + "'";
                }
                if (this.txtKSHEnd.Text.Trim().Length > 0)
                {
                    mWhere = mWhere + " And KSH <= '" + this.txtKSHEnd.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 导出数据到DBF

                #region 提供下载

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

                #endregion 提供下载

其它相关:
      
转自:http://www.cnblogs.com/jyshi/

时间: 2025-01-08 10:05:11

导出DBF,并且提供下载 .的相关文章

php导出csv数据在浏览器中输出提供下载或保存到文件的示例_php实例

1.在浏览器输出提供下载 复制代码 代码如下: /** * 导出数据到CSV文件 * @param array $data  数据 * @param array $title_arr 标题 * @param string $file_name CSV文件名 */function export_csv(&$data, $title_arr, $file_name = '') {    ini_set("max_execution_time", "3600");

Asp.net获取服务器指定文件夹目录文件并提供下载的方法

 这篇文章主要介绍了Asp.net获取服务器指定文件夹目录文件并提供下载的方法,涉及使用http协议操作文件的技巧,需要的朋友可以参考下 本文实例讲述了Asp.net获取服务器指定文件夹目录文件并提供下载的方法.分享给大家供大家参考.具体实现方法如下: 代码如下: string dirPath = HttpContext.Current.Server.MapPath("uploads/"); if (Directory.Exists(dirPath)) { //获得目录信息 Direc

ie浏览器不能下载东西提示没有提供下载的内容该怎么办

  有些时候听完一些老歌,想把它下载到自己电脑上,却发现没有提供下载,难道说就这样放弃了吗?答案是:不,那居然说不了又怎么样才能下载呢?这个也不难,只要利用IE完全可以解决. 1.启动IE,随便打开一个音乐网站.然后搜索首没有提供下载的歌曲.先看看这首歌,在正常情况下能不能下载呢?点下载没反应,因为下载是灰色的,也就是说没有提供下载.好了,剩下的就交给IE吧! 2.IE菜单单击,工具-Internet选项, 3.找到浏览历史记录,单击"设置". 4.在弹出对话框,点击"查看文

Web项目将word打包zip并提供下载

阅读目录 1. 后台处理的java 方法 2. Sping MVC框架实现下载遇到的"坑"  3. 生成zip包成功,在前端跳转下载页面 4. 流在不同web容器的妥善处理       该博客记录Java Web项目将word打包zip并提供下载功能的实现和其中遇到的坑,方便后续自己的查看的参照.      项目架构背景: JQuery + Bootstarp + SpringMvc 回到顶部 1. 后台处理的java 方法       实现思路:首先将所有的word生成到upload

结构-web开发--关于从页面导出dbf格式文件

问题描述 web开发--关于从页面导出dbf格式文件 从页面导出dbf文件字段之间的距离很大,不知道如何控制,求救....如图:![图片说明](http://img.ask.csdn.net/upload/201603/21/1458550761_92501.png) //代码如下 public static void writeDBF(String path, Object[][] data, String[] headColmuns) throws DBFException, FileNot

JSP从数据库导出数据到Excel下载的实现

JSP从数据库导出数据到Excel下载的实现 关键代码: <%@ page contentType="application/msexcel" %> <%    //response.setHeader("Content-disposition","inline; filename=videos.xls");    response.setHeader("Content-disposition","

JSP实现从数据库导出数据到Excel下载的方法_JSP编程

本文实例讲述了JSP实现从数据库导出数据到Excel下载的方法.分享给大家供大家参考,具体如下: 关键代码: <%@ page contentType="application/msexcel" %> <% //response.setHeader("Content-disposition","inline; filename=videos.xls"); response.setHeader("Content-disp

iOS开发UI篇—推荐两个好用的Xcode插件(提供下载链接)

这里推荐两款好用的Xcode插件,并提供下载链接. 一.插件和使用如下: 1.两款插件 对项目中图片提供自动提示功能的插件:KSImageNamed-Xcode-master 提供快速创建自动注释:VVDocumenter-Xcode-master 2.使用介绍: (1)KSImageNamed-Xcode-master的使用 安装该插件后,会对文件中图片进行智能提示. (2)VVDocumenter-Xcode-master能提供快速注释 只要在需要进行注释的地方敲三个斜杠(即///),就能根

servlet file 如何获取网络其他file server 的文件提供下载

问题描述 需要从fileserver读取文件提供下载,访问fileserver\\cnbdc01\it\tomliang\email\a.zip在开发环境下是可以访问到的,不部署到web服务上当部署到web上的时候,就提示fileisnotexists!Filef=newFile("\\cnbdc01\it\tomliang\email\a.zip");if(f.exists()){System.out.println("done");}else{System.ou