如何以pdf格式下载sqlserver中的表并在特定驱动器中下载 [英] How to download a table in sqlserver in pdf format and download in a particular drive

查看:79
本文介绍了如何以pdf格式下载sqlserver中的表并在特定驱动器中下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql server中有一个表现在我想以pdf格式下载表,并希望保存在具有floder名称的特定驱动器中,但是在用户中将看不到一个条件下载文件只是保存文件floder



我尝试过:



i have one table in sql server now i want to download the table in pdf format and want to be saved in a particular drive with a floder name but one condition download file will not be visible in user just save the file in particular floder

What I have tried:

Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=pratap.pdf");
            //Response.TransmitFile(FilePath);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
            GridView1.AllowPaging = true;
            GridView1.DataBind();

推荐答案

你不能这样做。

问题是最后一点:

You can't do it.
The problem is the final bit:
Quote:

但是一个条件下载文件在用户中将不可见只是保存文件特别是floder

but one condition download file will not be visible in user just save the file in particular floder

您的服务器完全无法控制您发送给用户的文件:您无法访问他的文件,文件夹,甚至无法确保文件被保存而不是查看或丢弃。出于安全原因,所有这一切完全取决于浏览器(以及它的设置) - 即使JavaScript代码也无法做到这一点!



要生成文件,请使用某些内容像iTextSharp: c# - 我们如何使用iTextSharp将数据表导出为PDF? - 堆栈溢出 [ ^ ]

Your server has no control at all over what happens to the file you sent to the user: you have no access to his files, folders, or even to ensure that the file is saved rather than viewed or discarded. All of that is entirely up to the browser (and it's settings) for security reasons - even JavaScript code can't do that!

To generate the file, use something like iTextSharp: c# - How can we export datatable to PDF using iTextSharp? - Stack Overflow[^]


这篇关于如何以pdf格式下载sqlserver中的表并在特定驱动器中下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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