Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable open/save prompt while saving pdf to server

Status
Not open for further replies.

theoryofben

IS-IT--Management
Aug 25, 2001
149
US
Hello,

I have reporting services report viewer. I am loading a server report to the viewer. This works fine. I have a button and when it is clicked, I want to export the report to PDF and save it on the server.

When the user clicks the button, the pdf is being saved just fine on the server, but I'm getting an open/save prompt anyway..even though the pdf has already been saved on the server. How can I disable that prompt?

Here is the code.

Code:
Dim warnings As Microsoft.Reporting.WebForms.Warning() = Nothing
            Dim streamids As String() = Nothing
            Dim mimeType As String = Nothing
            Dim encoding As String = Nothing
            Dim extension As String = Nothing
            Dim DeviceInfo As String = "<DeviceInfo>" _
                & "  <OutputFormat>PDF</OutputFormat>" _
                & "  <PageWidth>8.5in</PageWidth>" _
                & "  <PageHeight>11.5in</PageHeight>" _
                & "  <MarginTop>0.5in</MarginTop>" _
                & "  <MarginLeft>0.5in</MarginLeft>" _
                & "  <MarginRight>0.4in</MarginRight>" _
                & "  <MarginBottom>0.4in</MarginBottom>" _
                & "</DeviceInfo>"
            Dim bytes As Byte()
            bytes = rpv1.ServerReport.Render("PDF", DeviceInfo, mimeType, encoding, extension, streamids, warnings)

            Response.Clear()
            Response.ContentType = mimeType
            Response.AddHeader("content-disposition", "attachment; filename=Test7." & extension)
            Try

                File.WriteAllBytes("C:\onetwothree.pdf", bytes)
    
            Catch ex As Exception
                
            End Try

            Response.End()

What am I doing wrong? Any ideas?

________________________________________________
[sub]"I have not failed. I've just found 10,000 ways that won't work."-Thomas Edison[/sub]

 
the default behavior is to prompt the user to open/save/cancel on the client. You saved the file on the server, not the client. To by pass this and open the PDF directly in the browser change the content hearder to
Code:
Response.AddHeader("content-disposition", "inline; filename=Test7." & extension)
also remove the try/catch. you are just swallowing the exception which is the worst thing you can do. you will have no idea why it fails if/when it does fail.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Thanks for the help. Is there a way to just save it and not display it in any way?

Also, I had some error handling code in the try/catch block but removed it before posting for brevity.

________________________________________________
[sub]"I have not failed. I've just found 10,000 ways that won't work."-Thomas Edison[/sub]

 
once the file is saved (on the server) redirect the user to another page.
Code:
SaveFile();
Response.Redirect("anotherpage.aspx?querystring=value", false);
if you want to save the file on the client you either need to prompt the user to save/open/cancel, or display the report in the browser and have the user save the file.
You cannot have the server automatically save the file to an arbitrary location on the client's machine.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top