Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. WebClient Problems

WebClient Problems

Scheduled Pinned Locked Moved ASP.NET
csharpsysadminhelp
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bgates1970
    wrote on last edited by
    #1

    I'm trying to open a server side MS-Word document and present it client side. I just want the word document to appear inside the browser or open up for viewing. When I run the code I'm prompted to "Open" or "Save" the file. If I "Save" the file it is the file that I requested but if I "Open" I get the following error: "This file could not be found. Try one or more of the following: * Check the spelling of the name of the document. * Try a different file name." Code: Dim _webClient As New System.Net.WebClient Dim sURI aAs String = "file://C:\test.doc" Dim theBuffer As Byte() = _webClient.DownloadData(sURI) With Page.Response .ClearContent() .ContentType = "application/msword" .AddHeader("content-disposition", "attachement;filename=test.doc") .OutputStream.Write(theBuffer, 0, theBuffer.Length) .End End With _webClient.Dispose() bgates1970

    G 1 Reply Last reply
    0
    • B bgates1970

      I'm trying to open a server side MS-Word document and present it client side. I just want the word document to appear inside the browser or open up for viewing. When I run the code I'm prompted to "Open" or "Save" the file. If I "Save" the file it is the file that I requested but if I "Open" I get the following error: "This file could not be found. Try one or more of the following: * Check the spelling of the name of the document. * Try a different file name." Code: Dim _webClient As New System.Net.WebClient Dim sURI aAs String = "file://C:\test.doc" Dim theBuffer As Byte() = _webClient.DownloadData(sURI) With Page.Response .ClearContent() .ContentType = "application/msword" .AddHeader("content-disposition", "attachement;filename=test.doc") .OutputStream.Write(theBuffer, 0, theBuffer.Length) .End End With _webClient.Dispose() bgates1970

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Where is the document stored? If it's stored on the client computer, you can't load it that way. The file that you are trying to get with the DownloadData call is located on the server.

      bgates1970 wrote:

      If I "Save" the file it is the file that I requested

      Have you verified the contents of the file that you saved? I think that you will find that it's not at all the document that you have saved, but the error message.

      --- b { font-weight: normal; }

      B 1 Reply Last reply
      0
      • G Guffa

        Where is the document stored? If it's stored on the client computer, you can't load it that way. The file that you are trying to get with the DownloadData call is located on the server.

        bgates1970 wrote:

        If I "Save" the file it is the file that I requested

        Have you verified the contents of the file that you saved? I think that you will find that it's not at all the document that you have saved, but the error message.

        --- b { font-weight: normal; }

        B Offline
        B Offline
        bgates1970
        wrote on last edited by
        #3

        The file I'm trying to load is located on the server (Windows 2003 SP1). I have verified that the file that I "saved" is indeed the same file. bgates

        G 1 Reply Last reply
        0
        • B bgates1970

          The file I'm trying to load is located on the server (Windows 2003 SP1). I have verified that the file that I "saved" is indeed the same file. bgates

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Why on earth are you using a web request to open a file on the same server, then? Use the IO.File class to open it.

          --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups