C# 如何在MVC中通过对话框保存pdf文件

C# 如何在MVC中通过对话框保存pdf文件,c#,asp.net-mvc,pdf,savefiledialog,C#,Asp.net Mvc,Pdf,Savefiledialog,我想保存在用户想要的路径中生成的PDF文件,例如桌面或其他什么,我在同一页面中有两个按钮,第一个是生成报告,第二个是将报告保存为PDF,有人能帮我怎么做吗 PdfPTable table=新的PdfPTable(3); 表1.AddCell(“ID”); 表E.AddCell(“年龄”); 表E.AddCell(“名称”); lenthee=db.persons.ToArray().Length; 波斯[]阵型=新波斯[列涅]; array=db.persons.ToArray(); for(i

我想保存在用户想要的路径中生成的PDF文件,例如桌面或其他什么,我在同一页面中有两个按钮,第一个是生成报告,第二个是将报告保存为PDF,有人能帮我怎么做吗

PdfPTable table=新的PdfPTable(3);
表1.AddCell(“ID”);
表E.AddCell(“年龄”);
表E.AddCell(“名称”);
lenthee=db.persons.ToArray().Length;
波斯[]阵型=新波斯[列涅];
array=db.persons.ToArray();
for(int i=0;i
您无法将其保存到用户的机器上。您只需写出文档并让用户从服务器代码中选择保存它的位置,就无法将某些文件保存到用户的计算机上。您可以做的是,将文件/文件流返回到浏览器,并根据浏览器设置,要求用户下载/打开文件。看看post,你是说Sami Kuhmonen,我必须在浏览器中打开PDF文件,然后用户将其保存?你可以通过Response.TransmitFIle()之类的方式将其流式传输到浏览器。您可以将mime内容类型设置为可识别为pdf的类型,或者设置为其他类型,例如八位字节流,并且由于浏览器不知道如何处理mime类型,因此它会要求查看或保存。一个简单的例子是:
 PdfPTable tablee = new PdfPTable(3);
            tablee.AddCell("ID");
            tablee.AddCell("AGE");
            tablee.AddCell("NAME");
            lenthee = db.persions.ToArray().Length;
            persion[] array = new persion[lenthee];
            array = db.persions.ToArray();
            for (int i = 0; i < lenthee; i++)
            {
                tablee.AddCell(array[i].ID.ToString());
                tablee.AddCell(array[i].age.ToString());
                tablee.AddCell(array[i].name.ToString());
            }

            Document doc = new Document(PageSize.A4, 1, 1, 1, 1);

            // here i want to ask the user where to he want to save the file (dialog box)then put the path in (path String attribute)
             String path = "C:\\Users\\se\\Desktop\\test.pdf";
            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create));
            doc.Open();
            Paragraph s = new Paragraph("report");
            doc.Add(s);
            doc.Add(tablee);
            doc.Close();