关于提问 [英] Regarding to ask a Question

查看:81
本文介绍了关于提问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net的sqlserver数据库中上载和下载pdf文件?
谢谢.
D.K. Dixit

How to upload and download a pdf file in sqlserver database in asp.net?
Thanks.
D.K.Dixit

推荐答案

上传文件:
http://msdn.microsoft.com/en-us/library/aa479405.aspx [ ^ ]
使用ASP.NET上传文件 [如何将任何文件存储到SQL数据库 [
Uploading files :
http://msdn.microsoft.com/en-us/library/aa479405.aspx[^]
File Upload with ASP.NET[^]

Saving files in DB :
How To Store Any File into SQL Database[^]


在服务器上更新文件
to uplaod file on server
protected void btnSub_Click(object sender, EventArgs e)
    {
        try
        {
            string filename = FileUpload1.FileName;
            string filename1 = FileUpload2.FileName;
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Uploadform\\" + filename.Trim()));
            FileUpload2.PostedFile.SaveAs(Server.MapPath("~\\Uploadform\\" + filename1.Trim()));
            string path = "~\\Uploadform\\" + filename.Trim();
            string path1 = "~\\Uploadform\\" + filename1.Trim();
            SqlConnection con = new SqlConnection(str);
            cmd = new SqlCommand("Insert into Circular(title,type,url1,url2) values('" + txttitle.Text + "','" + txttype.Text + "','" + path + "','" + path1 + "')", con);
            lblinfo.Text = " Uploaded Successfully ";
            cmd.CommandType = CommandType.Text;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }


您的文件可以简单地下载/打开为


your file can be simply download/open as

Response.Redirect(pdfurlfetchfromdatabase);


意味着您需要在数据库中存储文件?如果我是罗格特,那么请阅读以下内容.

要将文件存储在数据库中,您需要将其转换为ByteArray [].您可以将dataType用作Image,Vatbinary.

要从数据库下载文件,您需要读取ByteArray并使用
将其写入pdf文件中 system.Io.WriteAllBytes()

这是
链接 [ ^ ]为您提供帮助.
Means you need to store a file in Database ? if i am roght then here read the following.

To store a file in database you need to convert it to ByteArray[]. You can use dataType as Image, Vatbinary.

To download file from database, you need to read ByteArray and write it on pdf file using
system.Io.WriteAllBytes()

here is link[^] for your help.


这篇关于关于提问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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