Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
bonina

Abrir documento em Word no lado do cliente

Recommended Posts

bonina

Boas!

Eu estou a tentar abrir um documento word do servidor no lado do cliente usando o seguinte código, arranjado num forum algures:

        Dim strPhysicalPath As String

        Dim objFileInfo As System.IO.FileInfo

        Try

            strPhysicalPath = "D:\Documentos\WordDocument.doc"

            If Not System.IO.File.Exists(strPhysicalPath) _

                Then Exit Sub

            objFileInfo = New System.IO.FileInfo(strPhysicalPath)

            Response.Clear()

            Response.ContentType = "application/octet-stream"

            Response.AddHeader("Content-Disposition", "attachment; filename=WordDocument.doc")

            Response.WriteFile(objFileInfo.FullName)

      Catch

      Finally

            Response.End()

        End Try

Este código está a abrir um documento word  em branco. Parece que o encontro, que o abre mas não o preenche!

Poderam ajudar-me?

Obrigado.

Share this post


Link to post
Share on other sites
bonina

Tentei novamente com um código semelhante:

Dim file As System.IO.FileInfo

        file = New System.IO.FileInfo(caminho)

        Response.Clear()

        Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)

        Response.AddHeader("Content-Length", file.Length.ToString())

        Response.ContentType = "application/octet-stream"

        Response.WriteFile(file.FullName)

        Response.End()

E actualmente funciona!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.