图片下载。。 那就这样 添加个aspx页 直接在后台把下面代码考过去using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.IO;namespace Qy.imagegl { public partial class imagexs : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int a = int.Parse(Request.QueryString["id"].ToString()); SqlConnection conn1 = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand cmd1 = new SqlCommand("select id,image_data from test where id=" + a + "", conn1); //固定显示Image_ID为3的图片 conn1.Open(); SqlDataReader sdr = cmd1.ExecuteReader(); if (sdr.Read()) { Response.BinaryWrite((byte[])sdr["image_data"]); } Response.End(); conn1.Close(); } } }然后把页面做为连接添加到 a标记里 就能下载了
{ }
protected void Button2_Click(object sender, EventArgs e)
{
//Response.Write();
if (this.fileUpload.PostedFile.FileName == "")
{
Response.Write("不能上传空文件");
return;
}
try
{
String path = Server.MapPath("upload/");//保存上传文件的文件夹upload虚拟路径对应的实际路径
string pt = path;
string fn = "";
if (!Directory.Exists(pt)) //如果文件夹不存在则创建
{
Directory.CreateDirectory(pt);
} string filePath = this.fileUpload.PostedFile.FileName;//客户端文件的实际地址
string serverPath = path + filePath.Substring(filePath.LastIndexOf("\\") + 1);//上传的文件保存在服务器端的路径
string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
System.Text.StringBuilder builder = new System.Text.StringBuilder(filePath);
builder.Append("<br/>上传文件的类型:" + this.fileUpload.PostedFile.ContentType.ToString() + Environment.NewLine + "");
builder.Append("<br/>客户端文件地址:" + this.fileUpload.PostedFile.FileName + Environment.NewLine + "");
builder.Append("<br/>上传文件的文件名:" + fileName + Environment.NewLine + "");
builder.Append("<br/>上传文件的扩展名:" + filePath.Substring(filePath.LastIndexOf(".") + 1) + Environment.NewLine + "");
builder.Append("<br/>上传文件的大小:" + this.fileUpload.PostedFile.ContentLength / 1024 + "k" + Environment.NewLine + "");
if (System.IO.File.Exists(serverPath))//判断服务器上是否有同名文件存在
{
this.lblState.Text = "这个文件在服务器上已经存在,请不要重复上传!";
return;
}
this.fileUpload.PostedFile.SaveAs(serverPath);//保存文件
this.lblState.Text = builder.ToString();
}
catch (Exception ex)
{
Response.Write(ex.Message); }
}
那就这样
添加个aspx页 直接在后台把下面代码考过去using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;namespace Qy.imagegl
{
public partial class imagexs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int a = int.Parse(Request.QueryString["id"].ToString());
SqlConnection conn1 = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand cmd1 = new SqlCommand("select id,image_data from test where id=" + a + "", conn1); //固定显示Image_ID为3的图片
conn1.Open();
SqlDataReader sdr = cmd1.ExecuteReader();
if (sdr.Read())
{
Response.BinaryWrite((byte[])sdr["image_data"]);
}
Response.End();
conn1.Close();
}
}
}然后把页面做为连接添加到 a标记里 就能下载了
图片的名字可以用guid方法来确定,那样不会有重复的图片名称;