Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Response.OutputStream在服务器中创建文件_C#_Asp.net_Stream - Fatal编程技术网

C# 从Response.OutputStream在服务器中创建文件

C# 从Response.OutputStream在服务器中创建文件,c#,asp.net,stream,C#,Asp.net,Stream,我有一个aspx页面,可以创建一个PDF文件下载到客户端的浏览器中,它运行良好。 但我也需要在服务器中创建该文件,这就是问题所在 如何将Response.OutputStream转换为服务器中的文件 这是我的密码: protected void Page_Load(object sender, EventArgs e) { try { JavaScriptSerializer jss = new JavaScriptSerializer(); D

我有一个aspx页面,可以创建一个PDF文件下载到客户端的浏览器中,它运行良好。 但我也需要在服务器中创建该文件,这就是问题所在

如何将Response.OutputStream转换为服务器中的文件

这是我的密码:

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        JavaScriptSerializer jss = new JavaScriptSerializer();

        DestinationPDF.DestinationPDF.DestinationPDFParameters dPdfParams = jss.Deserialize<DestinationPDF.DestinationPDF.DestinationPDFParameters>(Request["destinationPdfValue"]);
        dPdfParams.DocAttributes.MarginBottom = 10;
        dPdfParams.DocAttributes.MarginLeft = 10;
        dPdfParams.DocAttributes.MarginRight = 10;
        dPdfParams.DocAttributes.MarginTop = 10;
        dPdfParams.DocAttributes.FileName = "Acreditacion_" + Request["id"];

        DestinationPDF.DestinationPDF dPdf = new DestinationPDF.DestinationPDF(dPdfParams.Widgets,dPdfParams.DocAttributes);

        Response.AppendHeader("Content-disposition", string.Format("attachment;filename={0}", dPdf.GetFileName()));
        Response.ContentType = "application/pdf";


        dPdf.Save(Response.OutputStream);
        Stream stream = Response.OutputStream;
        var fileStream = new FileStream(@"C:\PROYECTOS 2013\CANCILLERIA\PortalTramites\PortalTramites\Documentos\pdf__Acreditacion" + Request["id"] + ".pdf", FileMode.Create, FileAccess.Write);
        stream.CopyTo(fileStream, 256);
    }
    catch (Exception ex) { Response.End(); }
    Response.End();
}
受保护的无效页面加载(对象发送方,事件参数e)
{
尝试
{
JavaScriptSerializer jss=新的JavaScriptSerializer();
DestinationPDF.DestinationPDF.DestinationPDFParameters dPdfParams=jss.Deserialize(请求[“destinationPdfValue]”);
dPdfParams.DocAttributes.MarginBottom=10;
dPdfParams.DocAttributes.MarginLeft=10;
dPdfParams.DocAttributes.MarginRight=10;
dPdfParams.DocAttributes.MarginTop=10;
dPdfParams.DocAttributes.FileName=“Acreditacion_u2;”+请求[“id”];
DestinationPDF.DestinationPDF dPdf=新的DestinationPDF.DestinationPDF(dPdfParams.Widgets,dPdfParams.DocAttributes);
AppendHeader(“内容处置”,string.Format(“附件;文件名={0}”,dPdf.GetFileName());
Response.ContentType=“application/pdf”;
dPdf.Save(Response.OutputStream);
Stream=Response.OutputStream;
var fileStream=new fileStream(@“C:\PROYECTOS 2013\CANCILLERIA\PortalTramites\PortalTramites\Documentos\pdf\uu Acreditacion”+请求[“id”]+.pdf],FileMode.Create,FileAccess.Write);
CopyTo(fileStream,256);
}
catch(异常ex){Response.End();}
Response.End();
}

您没有说您遇到了什么错误,但从路径上我猜是拒绝访问错误

如果是这样的话,那么基本上web服务器运行的windows用户没有所有计算机的权限,但只对某些文件夹有权限。 您可以使用Server.MapPath将文件保存在站点目录树中,
下面是一个例子

我的错误是用西班牙语抛出的,翻译是怎么回事:序列无法读取它。问题在于Response.OutputStream不可查找。代码中指定的路径是新文件的路径和名称。在这种情况下,您是否尝试使用MemoryStream包装OutputStream?