Wednesday, October 19, 2011

Opening a word/pdf

Word File
------------
 Dim sResponseFile As String = Server.MapPath(".") & "/desktopmodules/career/resume/" & CType(e.Item.FindControl("lblresumepath"), Label).Text

        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/msword"
        Response.AddHeader("Content-Disposition", "attachment; filename=""" & Path.GetFileName(sResponseFile) & """")
 Response.ContentEncoding = System.Text.Encoding.UTF7
        Response.Charset = ""
        Response.WriteFile(sResponseFile)
        Response.End()


PDF File
---------

Page.RegisterStartupScript("ReportViewer_ExportToPdf", "<script language=Javascript>window.open('PDF/Test9.pdf','_blank');</script>")


     Dim strPath = _Global.EBOOK_PATH
            Dim strFileName As String
            Dim absPath As String
            Dim vPath As String
            If e.CommandName = "Select" Then

                strFileName = e.Item.Cells(0).Text
                absPath = Server.MapPath("..") & "\" & strPath & strFileName
                vPath = "../" & strPath & strFileName
                vPath = vPath.Replace("\", "/")


                If File.Exists(absPath) Then
                    ScriptManager.RegisterClientScriptBlock(Me.Page, Page.GetType(), "Ebooks", "window.open('" & vPath & "','_blank','menubar=0, location=0, resizable=1, status=1, scrollbars=1');", True)
                Else
                    _Global.ShowErrorMessage(Me.Page, "File not found")
                End If

            End If

No comments:

Post a Comment