2014-09-14 1 views
0

클라이언트의 브라우저에 다운로드 할 PDF 파일을 만드는 aspx 페이지가 있는데 제대로 작동합니다. 하지만 그 파일을 서버에 생성해야하는데 그게 문제입니다.Response.OutputStream에서 서버에 파일 생성

어떻게 Response.OutputStream을 File로 변환하여 서버에 넣을 수 있습니까?

여기 내 코드입니다 :

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(); 
} 

답변

0

당신이지고 어떤 오류 말했다하지 못했지만, 길에서 나는 오류 액세스 거부 추측하고있다.

그렇다면 기본적으로 웹 서버는 모든 컴퓨터에 대한 permitions이없는 Windows 사용자와 함께 실행되지만 특정 폴더에만 해당됩니다. Server.MapPath를 사용하여 사이트 디렉토리 트리에 파일을 저장할 수 있습니다. 여기에 예제가 있습니다. Save file to web server

+0

내 오류가 스페인어로 throw됩니다. 번역은 다음과 같이 어떻게 수행됩니까? 순서는 읽을 수 없습니다. 문제는 Response.OutputStream이 Seekable이 아니기 때문입니다 – CHIRINGUCHI

+0

코드에 지정된 경로가 새 파일의 경로와 이름입니다 – CHIRINGUCHI

+0

이 경우 OutputStream을 MemoryStream으로 래핑하려고 했습니까? –