C# 在运行发布站点的远程客户端计算机上下载pdf文件

C# 在运行发布站点的远程客户端计算机上下载pdf文件,c#,C#,我已经发布了我的站点并从远程位置访问它,但是当我下载pdf文件时,它被下载并保存在我发布代码的服务器端 int FOrgCountRows = OrgCountRows; string folderName = @"c:\EStatement\"; foreach (DataRow dr in DTAC.Rows) {

我已经发布了我的站点并从远程位置访问它,但是当我下载pdf文件时,它被下载并保存在我发布代码的服务器端

                    int FOrgCountRows = OrgCountRows;
                    string folderName = @"c:\EStatement\";

                        foreach (DataRow dr in DTAC.Rows)
                        {
                            if (DTAC.Rows[FOrgCountRows - OrgCountRows]["Acc"].ToString() == AccArray[CountAcc].ToString())
                            {
                                DataT.ImportRow(dr);
                                if((FOrgCountRows - OrgCountRows)!=( DTAC.Rows.Count)-1)
                                OrgCountRows--;
                                DTACCount++;
                            }

                            if (DTAC.Rows[FOrgCountRows - OrgCountRows]["Acc"].ToString() != AccArray[CountAcc].ToString())
                            {
                                string fileName = "_" + AccArray[CountAcc] + ".pdf";
                                CountAcc++; 
                                string extension;
                                string encoding;
                                string mimeType;
                                string[] streams;
                                Warning[] warnings;

                                LocalReport report = new LocalReport();
                                report.ReportPath = Server.MapPath("~/Rpt123.rdlc");
                                ReportDataSource rds = new ReportDataSource();
                                rds.Name = "DataSet1";
                                rds.Value = DataT;
                                report.DataSources.Add(rds);

                                byte[] mybytes = report.Render("PDF", null, out extension, out encoding, out mimeType, out streams, out warnings); //for exporting to PDF  

                                if (!System.IO.File.Exists(folderName))
                                {
                                    using (FileStream fs = File.Create(folderName + fileName)) 
                                    {
                                        fs.Write(mybytes, 0, mybytes.Length);
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("File \"{0}\" already exists.", fileName);
                                    return;
                                }

                                Response.Buffer = true;
                                Response.Clear();
                                Response.ContentType = contentType;
                                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                                Response.WriteFile(folderName + fileName);
---字符串folderName=@c:\EStatement\;这是目标文件夹。。我想下载客户端计算机上此指定文件夹上的文件。。任何解决方案?

可能重复:

无论如何:

Filestream将写入服务器上的文件,而不是客户端计算机上的文件

尝试将文档字节写入响应输出流,并将内容处置http头写入响应

Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

这将根据浏览器设置提示用户下载文件


您无法控制客户端计算机中的哪个目录文件。

Ok。让我试试这个,然后返回给你。谢谢你,这个文件还是在服务器上下载的。是的,它可以精确地输出。非常感谢StefanoMaybe您可以签名作为答案: