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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Word Document in Browser From SQL 2000

Word Document in Browser From SQL 2000

Scheduled Pinned Locked Moved ASP.NET
helpdatabasesql-serversysadminquestion
2 Posts 2 Posters 0 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.
  • M Offline
    M Offline
    Mike L
    wrote on last edited by
    #1

    Hi, I'm hoping someone can help me with a problem - I'm a newbie, and trying to write a somewhat simple app. I've gotten Word documents uploaded to my SQL server, using the FileUpload Demo as a model. With the documents in SQL Server (image column), I need to be able to pull them out and open them, either in a browser window, or in the Word app - either one is fine. The code below shows how I'm trying it now, but it seems that since I'm writing out to the .aspx page using Response. OutputStream, the application doesn't see it as a Word document, even though I've set the ContentType properly as "application/msword". They are retrieved from the SQL server OK - my problem is opening them either in the browser (preferred) or in the Word app. On my laptop, they open as gibberish in Front Page, rather than Word. Can someone show me the error of my ways and help me fix this problem? I'd really, really appreciate it! My code to do this is as follows: private void ShowTheFile(long FileID) { // Define SQL select statement string SQL = "SELECT FileSize, FileData, ContentType, FileName FROM tUserDocuments WHERE UniqueFileID = " + FileID.ToString(); // Create Connection object SqlConnection sqlCon = new SqlConnection(RM.GetConnString()); // Create Command Object SqlCommand sqlComm = new SqlCommand(SQL, sqlCon); // Open Connection sqlCon.Open(); // Execute command and receive DataReader SqlDataReader dbRead = sqlComm.ExecuteReader(); // Read row dbRead.Read(); // Clear Response buffer Response.Clear(); string conType = RM.Clean((string)dbRead["ContentType"]); byte[] fileData = (byte[])dbRead["FileData"]; int fileSize = (int)dbRead["FileSize"]; long fileID = FileID; string fileName = RM.Clean((string)dbRead["Filename"]); // Set ContentType to the ContentType of our file Response.ContentType = conType; // Write data out of database into Output Stream Response.OutputStream.Write(fileData, 0, fileSize); // Close database connection sqlCon.Close(); // End the page Response.End(); } Thanks VERY much for any help you can give. Mike in Bangkok -- modified at 0:55 Monday 12th September, 2005

    E 1 Reply Last reply
    0
    • M Mike L

      Hi, I'm hoping someone can help me with a problem - I'm a newbie, and trying to write a somewhat simple app. I've gotten Word documents uploaded to my SQL server, using the FileUpload Demo as a model. With the documents in SQL Server (image column), I need to be able to pull them out and open them, either in a browser window, or in the Word app - either one is fine. The code below shows how I'm trying it now, but it seems that since I'm writing out to the .aspx page using Response. OutputStream, the application doesn't see it as a Word document, even though I've set the ContentType properly as "application/msword". They are retrieved from the SQL server OK - my problem is opening them either in the browser (preferred) or in the Word app. On my laptop, they open as gibberish in Front Page, rather than Word. Can someone show me the error of my ways and help me fix this problem? I'd really, really appreciate it! My code to do this is as follows: private void ShowTheFile(long FileID) { // Define SQL select statement string SQL = "SELECT FileSize, FileData, ContentType, FileName FROM tUserDocuments WHERE UniqueFileID = " + FileID.ToString(); // Create Connection object SqlConnection sqlCon = new SqlConnection(RM.GetConnString()); // Create Command Object SqlCommand sqlComm = new SqlCommand(SQL, sqlCon); // Open Connection sqlCon.Open(); // Execute command and receive DataReader SqlDataReader dbRead = sqlComm.ExecuteReader(); // Read row dbRead.Read(); // Clear Response buffer Response.Clear(); string conType = RM.Clean((string)dbRead["ContentType"]); byte[] fileData = (byte[])dbRead["FileData"]; int fileSize = (int)dbRead["FileSize"]; long fileID = FileID; string fileName = RM.Clean((string)dbRead["Filename"]); // Set ContentType to the ContentType of our file Response.ContentType = conType; // Write data out of database into Output Stream Response.OutputStream.Write(fileData, 0, fileSize); // Close database connection sqlCon.Close(); // End the page Response.End(); } Thanks VERY much for any help you can give. Mike in Bangkok -- modified at 0:55 Monday 12th September, 2005

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      hi there, Maybe u r lacking of this statement: Response.AppendHeader("Content-Disposition", "attachment;filename=word.doc"); try this << >>

      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