Problem with pdf viewing in IE

Discussion in 'ASP .Net' started by =?Utf-8?B?UGF0TGFm?=, Feb 27, 2004.

  1. Hello to all
    I have created an asp.net application that needs to view pdf documents. I ran into a security issue but I added the identity impersonate = true and turned off anonymous access to the site to combat that but now when I run the application instead of the pdf being viewed from IE it prompts me to either open it or download it. When I choose to open it the page opens in notepad and not acrobat. Can anyone think of why this would happen?

    Thanks
    PatLaf
    =?Utf-8?B?UGF0TGFm?=, Feb 27, 2004
    #1
    1. Advertising

  2. MIME type on the IIS server is my first guess. When the MIME type is not
    set, it will try to download as an unknown file type and make a best guess
    as to what program it is opened in. This is a server side issue, not a
    client side, unless the client does not have Acrobat.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    **********************************************************************
    Think Outside the Box!
    **********************************************************************
    "PatLaf" <> wrote in message
    news:...
    > Hello to all,
    > I have created an asp.net application that needs to view pdf documents. I

    ran into a security issue but I added the identity impersonate = true and
    turned off anonymous access to the site to combat that but now when I run
    the application instead of the pdf being viewed from IE it prompts me to
    either open it or download it. When I choose to open it the page opens in
    notepad and not acrobat. Can anyone think of why this would happen?
    >
    > Thanks,
    > PatLaf
    Cowboy \(Gregory A. Beamer\), Feb 27, 2004
    #2
    1. Advertising

  3. Some things I forgot to mention...The client does have acrobat installed and if I try to open another pdf doc it works.....I'm stumped

    Thanks in advance
    Patrick Laferriere
    =?Utf-8?B?UGF0TGFm?=, Feb 27, 2004
    #3
  4. Thanks for Cowboy's informative suggestions.

    Hi PatLaf,

    I think you may try Cowboy's suggestion to have a check on the page's mime
    setting to see whether it has been set to the proper value according to pdf
    :
    application/pdf

    If you still feel anything unclear or have any problems, would you please
    provide some infos on your page code so as for us to do some further
    research? Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Feb 28, 2004
    #4
  5. I am posting the code in hopes that someone can help. I don't know why this is happening because it worked the day I built it then on Wednesday last week our network updates took place and now it doesn't. Might be a red herring but I'm not sure....here's the code..

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Clic
    Dim sPrefix As String = "WO_
    Dim sWildcard As String = "*.pdf
    Dim sFilePath As String = ConfigurationSettings.AppSettings("RoutingSheetPath") & "\
    Tr
    If Not txtWoNum.Text.Length = 10 The
    Dim scriptString As String = "<script language=JavaScript> alert('Work Order Number must be 10 digits in length!');</script>
    If (Not IsClientScriptBlockRegistered("clientScript")) The
    RegisterClientScriptBlock("clientScript", ScriptString
    Exit Su
    End I
    ElseIf Not IsNumeric(txtWoNum.Text.Trim) The
    Dim scriptString As String = "<script language=JavaScript> alert('Work Order Number must be numeric!');</script>
    If (Not IsClientScriptBlockRegistered("clientScript")) The
    RegisterClientScriptBlock("clientScript", ScriptString
    Exit Su
    End I
    End I

    Dim sFiles As String() = System.IO.Directory.GetFiles(sFilePath, sPrefix & txtWoNum.Text.Trim & sWildcard

    If sFiles.Length > 0 The
    'Set the appropriate ContentType
    Response.ContentType = "Application/pdf
    'Write the file directly to the HTTP output stream
    Response.WriteFile(sFiles(0)
    'Response.End(
    Exit Su
    Els
    Dim scriptString As String = "<script language=JavaScript> alert('Routing sheet was not found!');</script>
    If (Not IsClientScriptBlockRegistered("clientScript")) The
    RegisterClientScriptBlock("clientScript", ScriptString
    End I
    Exit Su
    End I

    Catch Err As Exceptio
    Me.lblWoNum.Visible = Fals
    Me.txtWoNum.Visible = Fals
    Me.btnSubmit.Visible = Fals
    Me.imglogo.visible = Fals
    Response.Write(Err.ToString
    Dim scriptString As String = "<script language=JavaScript> alert('Unkown error accessing web site!');</script>
    If (Not IsClientScriptBlockRegistered("clientScript")) The
    RegisterClientScriptBlock("clientScript", ScriptString
    Exit Su
    End I

    End Tr

    End Su

    THanks in advance,
    =?Utf-8?B?UGF0TGFm?=, Mar 1, 2004
    #5
  6. Hi PatLaf,

    Thanks for your followup and the code you provided. From your code I found
    that you use
    Response.ContentType = "Application/pdf"
    Response.WriteFile( filepath) .
    to show the pdf to client.
    And this code block is called in a button's post back event. I think you
    need to first clear all the original headers and content before you set the
    Response.ContentType and write the pdf file to the output stream. Also, use
    Response.End to endup the Response operation after write file. Here is the
    code I used:
    ----------------------------------------------------
    Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnShow.Click
    If txtFilename.Text.Length > 0 Then
    Dim strPath As String
    ' change the path according to your web folder structure
    strPath = Server.MapPath("PDF/") + txtFilename.Text

    If System.IO.File.Exists(strPath) Then
    'do clear operation
    Response.ClearHeaders()
    Response.ClearContent()
    Response.Clear()
    Response.ContentType = "Application/pdf"
    ' add the below sentense if you want to force the client to
    open a file open dialog
    Response.AddHeader("content-disposition", "attachment;
    filename=" + txtFilename.Text)
    Response.WriteFile(strPath)
    'End the response stream
    Response.End()
    Else
    lblMessage.Text = "Invalid filename!"
    End If
    Else
    lblMessage.Text = "Please enter filename!"
    End If
    End Sub

    ----------------------------------------------------
    Also, I've attached the whole test page I used on my side which worked
    well. You may have a try on it to see if it works on side.

    In addition, I've found that you've posted two new thread on this issue and
    some other community members and MSFT member have also replied you in
    those. Please also have a look to see whether those help. If you have
    anything unclear or any further problems, please feel free to post here or
    in those threads.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Mar 2, 2004
    #6
  7. Hi PatLaf,

    Have you had a chance to try out my suggestions or have you resolved this
    problem? IF you have any further questions, please feel free to post here.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Mar 4, 2004
    #7
  8. I copied the code behind page's submit button logic into a new form and
    it worked as it should. I don't know why.

    Thanks in advance,
    PatLaf


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Patrick Laferriere, Mar 4, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Lawrence [MSFT]

    Re: Still problems viewing pdf in IE...posting code

    Eric Lawrence [MSFT], Mar 1, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    610
    john farrow
    Mar 2, 2004
  2. =?Utf-8?B?SmVuQw==?=

    Importing/Viewing PDF documents

    =?Utf-8?B?SmVuQw==?=, May 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    344
    Jason DeFontes
    May 10, 2004
  3. Jandaman

    Viewing PDF's in a DIV

    Jandaman, Aug 13, 2004, in forum: HTML
    Replies:
    2
    Views:
    1,209
    Jukka K. Korpela
    Aug 14, 2004
  4. Ricardo Pog
    Replies:
    1
    Views:
    376
    Austin Ziegler
    Mar 26, 2008
  5. Sean Nakasone
    Replies:
    1
    Views:
    325
    Farrel Lifson
    Apr 14, 2008
Loading...

Share This Page