Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Opening MS WORD document from database

Reply
Thread Tools

Opening MS WORD document from database

 
 
Simon
Guest
Posts: n/a
 
      10-27-2005
I'm simplying trying to download and and open word documents that are stored
in the database. I figured out how to uploaded the documents as Byte, but I
can't figure out how to get them back out properly. The following code is
what I've tried (vb.NET)... It goes as far as asking me to Save/Open the
file, but when I do, the contents of the documents is the webage that the
download link was on! I'm fairly new to programming/web development, so i'm
not totally sure what i'm doing. I hope i've included enough information.

Thanks in advance!

Simon

--- VB.NET code ---

Public Sub DownloadFile(ByVal File_Id As Integer)
Dim dr As SqlDataReader
Try
Me.OpenConnection(ConfigurationSettings.AppSetting s("MD_Runs_Connection_String"))

Dim sqlCmd As New SqlCommand("usp_files_s_by_file_id", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.Add(New SqlParameter("@file_id", File_Id))

dr = sqlCmd.ExecuteReader()

Do While dr.Read
Dim file() As Byte = CType(dr.Item("fileData"), Byte())
memStream.Write(file, 0, file.Length)
Loop

memStream.Flush()
ContentType = dr.Item("Application/octet-stream")

Catch
Throw
Finally
dr.Close()
Me.CloseConnection()
End Try
End Sub


 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFzb24gQ2h1?=
Guest
Posts: n/a
 
      10-27-2005
I'm a C# programmer...so bare with it.
you would need to put that byte[] into the Response.OutputStream.
so..
Response.OutputStream.Write(byte[],0,the length);

along with the Response.ContentType set correctly, the browser will be able
to handle it as a word file.

Response.OutputStream will essentially turn your aspx file into a doc
file...so the wordopener.aspx when you browse it...it'll be treated as a doc
file...so nothing in the html tags would matter, as you won't see them.

and when you're finished...end with Response.End


"Simon" wrote:

> I'm simplying trying to download and and open word documents that are stored
> in the database. I figured out how to uploaded the documents as Byte, but I
> can't figure out how to get them back out properly. The following code is
> what I've tried (vb.NET)... It goes as far as asking me to Save/Open the
> file, but when I do, the contents of the documents is the webage that the
> download link was on! I'm fairly new to programming/web development, so i'm
> not totally sure what i'm doing. I hope i've included enough information.
>
> Thanks in advance!
>
> Simon
>
> --- VB.NET code ---
>
> Public Sub DownloadFile(ByVal File_Id As Integer)
> Dim dr As SqlDataReader
> Try
> Me.OpenConnection(ConfigurationSettings.AppSetting s("MD_Runs_Connection_String"))
>
> Dim sqlCmd As New SqlCommand("usp_files_s_by_file_id", sqlConn)
> sqlCmd.CommandType = CommandType.StoredProcedure
> sqlCmd.Parameters.Add(New SqlParameter("@file_id", File_Id))
>
> dr = sqlCmd.ExecuteReader()
>
> Do While dr.Read
> Dim file() As Byte = CType(dr.Item("fileData"), Byte())
> memStream.Write(file, 0, file.Length)
> Loop
>
> memStream.Flush()
> ContentType = dr.Item("Application/octet-stream")
>
> Catch
> Throw
> Finally
> dr.Close()
> Me.CloseConnection()
> End Try
> End Sub
>
>
>

 
Reply With Quote
 
 
 
 
Simon
Guest
Posts: n/a
 
      10-28-2005
Thanks for the tips! I was about to try it out, but got a Configuration
Error this morning, with "Interop.Microsoft.Office.Core" =( Thanks for
your quick response though.

Simon

"Jason Chu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm a C# programmer...so bare with it.
> you would need to put that byte[] into the Response.OutputStream.
> so..
> Response.OutputStream.Write(byte[],0,the length);
>
> along with the Response.ContentType set correctly, the browser will be
> able
> to handle it as a word file.
>
> Response.OutputStream will essentially turn your aspx file into a doc
> file...so the wordopener.aspx when you browse it...it'll be treated as a
> doc
> file...so nothing in the html tags would matter, as you won't see them.
>
> and when you're finished...end with Response.End
>
>
> "Simon" wrote:
>
>> I'm simplying trying to download and and open word documents that are
>> stored
>> in the database. I figured out how to uploaded the documents as Byte,
>> but I
>> can't figure out how to get them back out properly. The following code
>> is
>> what I've tried (vb.NET)... It goes as far as asking me to Save/Open the
>> file, but when I do, the contents of the documents is the webage that the
>> download link was on! I'm fairly new to programming/web development, so
>> i'm
>> not totally sure what i'm doing. I hope i've included enough
>> information.
>>
>> Thanks in advance!
>>
>> Simon
>>
>> --- VB.NET code ---
>>
>> Public Sub DownloadFile(ByVal File_Id As Integer)
>> Dim dr As SqlDataReader
>> Try
>>
>> Me.OpenConnection(ConfigurationSettings.AppSetting s("MD_Runs_Connection_String"))
>>
>> Dim sqlCmd As New SqlCommand("usp_files_s_by_file_id",
>> sqlConn)
>> sqlCmd.CommandType = CommandType.StoredProcedure
>> sqlCmd.Parameters.Add(New SqlParameter("@file_id", File_Id))
>>
>> dr = sqlCmd.ExecuteReader()
>>
>> Do While dr.Read
>> Dim file() As Byte = CType(dr.Item("fileData"), Byte())
>> memStream.Write(file, 0, file.Length)
>> Loop
>>
>> memStream.Flush()
>> ContentType = dr.Item("Application/octet-stream")
>>
>> Catch
>> Throw
>> Finally
>> dr.Close()
>> Me.CloseConnection()
>> End Try
>> End Sub
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
RE: Opening MS WORD document from database Simon ASP .Net 3 11-09-2005 09:17 PM
RE: Opening MS WORD document from database Simon ASP .Net 1 11-09-2005 01:25 AM
Word file not opening from Adm -My recent docs but opening from file menu of Word Thaqalain Computer Support 0 06-30-2005 02:20 AM



Advertisments