从数据库将图像保存回我们的PC [英] Save images back to our PC from DataBase

查看:58
本文介绍了从数据库将图像保存回我们的PC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含图像表的数据库.一切正常.它使用文件上载控件上载图像,并使用DataList控件检索图像.

我的主要问题是,如果你们中的任何人都注意到,当我们右键单击来自数据库的图像以将其保存在我们的PC中时,该选项为保存图像...".不在列表中.我希望我的网站用户通过右键单击图像将这些图像保存在他/她的PC中.

任何人都可以建议如何使用户能够通过右键单击图像将图像保存到他/她的PC中吗?
还是有其他方法可以将数据库中的图像保存/下载回我们的PC?

I have one database containing image table. It is working fine. It uploads images using file upload control and retrieves images using DataList control.

My main problem is if anyone of you have noticed that when we right click on the image coming from the database to save it in our PC, the option "save image. . ." is not coming in the list. I want my website''s user to save these images in his/her PC by right click on the image.

Can anyone suggest how to make the user able to save images into his/her PC by right clicking on the image?
Or is there any other way to save/download images from database back to our PC?

推荐答案

我使用的是ASPX文件:
I use an ASPX file:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="wm5ftdl.aspx.cs" Inherits="wm5ftdl" %>

<%
    // Send a download file to the client given the filename.
    string guid = Request.QueryString["file"];
    string fileName = "ERROR";
    byte[] data = new byte[] { 0, 0, 0, 0 };
    string strCon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DownloadDatabase"].ConnectionString;
    using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strCon))
        {
        con.Open();
        string strcmd = "SELECT [iD] ,cn.[fileName],[description] ,[dataContent] ,[version] " +
                        "FROM dlContent cn " +

                        "WHERE cn.iD=@ID";
        using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strcmd, con))
            {
            cmd.Parameters.AddWithValue("@ID", guid);
            using (System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader())
                {
                if (r.Read())
                    {
                    fileName = (string) r["filename"];
                    data = (byte[]) r["dataContent"];
                    }
                }
            }
        }
    Response.Clear();
    Response.AddHeader("Cache-Control", "no-cache, must-revalidate, post-check=0, pre-check=0");
    Response.AddHeader("Pragma", "no-cache");
    Response.AddHeader("Content-Description", "File Download");
    Response.AddHeader("Content-Type", "application/force-download");
    Response.AddHeader("Content-Transfer-Encoding", "binary\n");
    Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
    Response.BinaryWrite(data);
    Response.End();
%>



然后,我可以将其链接设置为



I can then set links to it as

href=\"wm5ftdl.aspx?file=IdOfImage"


这篇关于从数据库将图像保存回我们的PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆