附件下载功能
来源:互联网 发布:手机淘宝电影在线看 编辑:程序博客网 时间:2024/05/17 01:42
1、下载链接
<a href='<%=Request.ApplicationPath%>/CommonPages/RetrieveImageData.aspx?TableName=Knowledge&FieldName=Upload&RowGuid=<%#Eval("RowGuid") %>'> 下载 </a>
2、下载功能调用页面:
RetrieveImageData.aspx
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RetrieveImageData.aspx.cs" Inherits="RongGuangSys.RongGuangTable.CommonPages.RetrieveImageData" theme="" styleSheetTheme=""%>
3、后台功能实现
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace CommonPages{ public partial class RetrieveImageData : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { Response.Clear(); string TableName = Request.QueryString["TableName"]; string FieldName = Request.QueryString["FieldName"]; string RowGuid = Request.QueryString["RowGuid"]; MisGuidRow oRow = new MisGuidRow(TableName, RowGuid); if (Request["TempFile"] != null) { string fileName = ""; #region 如果采用生成文件的方式,会在服务器的Web程序目录下面创建临时文件, if (oRow.R_HasFilled && !Convert.IsDBNull(oRow[FieldName])) { if (oRow[FieldName + "_FileName"] != null) { fileName = oRow[FieldName + "_FileName"].ToString(); } else { fileName = Guid.NewGuid().ToString(); } //替换开始 string guid = System.Guid.NewGuid().ToString(); FileStream objFileStream; BinaryWriter objBinaryWriter; string attPath = Request.ApplicationPath + "/RongGuangTempFile/" + TableName; if (!Directory.Exists(Server.MapPath(attPath))) { Directory.CreateDirectory(Server.MapPath(attPath)); } string strFullFilePath = Server.MapPath(attPath + "/" + fileName); //二进制文件写必须用binaryWrite,不需要制定encoding方式 if (!File.Exists(strFullFilePath)) { objFileStream = new FileStream(strFullFilePath, FileMode.OpenOrCreate, FileAccess.Write); objBinaryWriter = new BinaryWriter(objFileStream); objBinaryWriter.Write((byte[])oRow[FieldName]); objBinaryWriter.Close(); objFileStream.Close(); } Response.Redirect(attPath + "/" + fileName); } #endregion } else { if (oRow.R_HasFilled && !Convert.IsDBNull(oRow[FieldName])) { //Response.Charset = "utf-8"; //Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");//'解决中文乱码之关键 Response.ContentType = oRow[FieldName + "_ContentType"].ToString(); if (oRow[FieldName + "_ContentType"].ToString().IndexOf("image/") < 0 && oRow[FieldName + "_FileName"] != null) { Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(oRow[FieldName + "_FileName"].ToString(), System.Text.Encoding.UTF8)); } Response.BinaryWrite((byte[])oRow[FieldName]); Response.End(); } } } }}
0 0
- JSP附件下载功能
- 附件下载功能
- Oracle EBS附件下载功能
- EBS开发附件上传和下载功能
- Struts2.0实现的文件上传(单附件和多附件)以及附件下载功能
- Struts2.0实现的文件上传(单附件和多附件)以及附件下载功能
- Struts2.0实现的文件上传(单附件和多附件)以及附件下载功能
- 附件功能
- 下载附件
- 附件下载
- 附件下载
- 附件下载
- 附件下载
- 附件下载
- 要用ASP.NET实现邮箱中附件下载的功能
- 要用ASP.NET实现邮箱中附件下载的功能
- 页面打包下载功能(包括页面上带的附件)
- SSH框架上传附件及下载功能的实现
- nctf-php
- SQLserver连接错误,错误代号2
- Ajax复选框多选删除的实现
- Swift 中枚举高级用法及实践
- WiBRAS宽带网络接入网关
- 附件下载功能
- HDU 5631 Rikka with Graph
- Vulkan教程
- 内建模块-urllib
- MYSQL必知必会读书笔记 第十二和十三章 分组数据
- Lua编程基础
- jsp ,servlet 中文乱码问题
- 文件切割机
- 算法导论之NP完全性和近似算法