473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Formatting a BinaryStream for output to Word doc

Hello,

Here is the code. followed by an explanation for what I am trying to
do. In particular, this line: BinaryStream.Write byteArray 'Need to
format
<%Response.Buffer=0 %>
<!--#include file="global.asp" -->

<%
Dim oUpload, oUploadCopy, oFiles, oForm, oFilesCopy, oFormCopy

Server.ScriptTimeout = 600
Set oUpload = Server.CreateObject("asppw.upload")
'Set properties first
'oUpload.FileExtensionList = "txt,gif,jpg,tif,doc,bmp,xls"
'oUpload.MaxFileSize = 10 * 1024 * 1024
'oUpload.UserDiskQuota = 20 * 1024 * 1024

'Now we can parse the uploaded stream
On Error Resume Next
oUpload.Upload

ChkError "Upload failed:"

Set oFiles = oUpload.UploadedFileInfo
Set oForm = oUpload.Form

Dim sFileName, lFileLength, byteArray, sDirectory

byteArray = oUpload.GetUploadedFileBlob("documentFile",sFileNa me
,lFileLength )
ChkError "Upload File Blob failed:"

Const adTypeBinary = 1
Const adTypeText = 2

Const adSaveCreateOverWrite = 2

'Create Stream objects
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write byteArray
Set fs=CreateObject("Scripting.FileSystemObject")
sOrder = oForm("orderNumber")
sVersion = oForm("versionNumber")
sExtenstion = oForm("extensionNumber")
'sRootFolder = Server.mappath("/Fupload") + "\Upload"

'RemoteHost = Request.ServerVariables("REMOTE_HOST")

If Request.ServerVariables("REMOTE_HOST") = "192.168.112.41" Then
sRootFolder = ("\\it1\ETS2DocApp\ETS Documents")
Else
sRootFolder = ("\\it1\ETS2DocApp\ETS Test Docs")
End If

'create Order subfolder
If sOrder <> "" then
If not fs.FolderExists(sRootFolder & "\" & sOrder) Then
fs.CreateFolder(sRootFolder & "\" & sOrder)
End If
sDirectory = sRootFolder & "\" & sOrder
End If

'create Version subfolder
If sVersion<>"" Then
If Not fs.FolderExists(sRootFolder & "\" & sOrder & "\" & sVersion)
Then
fs.CreateFolder(sRootFolder & "\" & sOrder & "\" & sVersion)
End If
sDirectory = sRootFolder & "\" & sOrder & "\" & sVersion
End If

'create Extension subfolder
If sExtenstion <>"" then
If not fs.FolderExists(sRootFolder & "\" & sOrder & "\" & sVersion &
"\" & sExtenstion) Then
fs.CreateFolder(sRootFolder & "\" & sOrder & "\" & sVersion & "\" &
sExtenstion)
End If
sDirectory = sRootFolder & "\" & sOrder & "\" & sVersion & "\" &
sExtenstion
End If

' Get document path on server
Dim strFilePathOnServer

strFilePathOnServer = sDirectory & "\" & sFileName

If fs.FileExists(strFilePathOnServer) Then
'Response.write "1"
On Error Resume Next
BinaryStream.LoadFromFile strFilePathOnServer
'Response.write strFilePathOnServer
If Err.number = 3002 Then
Response.Write("3002")
' Throw error message in DocumentManagerProxy
Response.End
End If
End If

BinaryStream.Write byteArray 'Need to format

If not Err Then
' Save binary data To disk
'Response.write "2"
BinaryStream.SaveToFile sDirectory + "\" + sFileName,
adSaveCreateOverWrite
'Response.write "3"
Response.Write sDirectory & "\" & sFileName '& RemoteHost
End If
Set BinaryStream=Nothing

%>
I am using an ASP that uses a third party active-x control to upload a
file to a file server using the ADO Stream Object. It uses the
FileSystemObject to create folders and files, which works fine. If the
file does not exist, it saves the file (Word.doc), if it does exists,
it checks to see if the file is open. If it is open, and another user
is trying to save or overwrite the same file, I trap an Error 3002
(document open), which another application picks up and throws an
exception. If it is open, and another user is trying to save or
overwrite this file, but no one has it open, it is not overwriting. I
realized that what is happening is if the file is created the first
time, I do a saveToFile, which works fine, and if the file is opened
and the Error 3002 is trapped, it does a loadFromFile and behaves
correctly as well. However, what is happening is if the file exists
but is not open, it is still doing a loadFromFile, and the bytearray I
am returning from the BinaryStream is only returning the file name,
corrupting the word document. So, I tried creating a separate
BinaryStream and did a copyTo a fresh BinaryStream - didn't work, then
just a separate BinaryStream which almost works - I am getting the
file to be saved and overwritten, but when I open the file it is rtf
code. I tried several methods to encode it properly, but nothing I try
seems to work. If I could figure out how to convert this second
BinaryStream to a Word doc my problem would be solved. Is there any
way to force a conversion of a bytearray returned from a Binary Stream
to a Word doc? I tried doing a "Write" and "WriteToText" and that
doesn't seem to work, and tried it with these constants: adTypeBinary
1, adTypeText 2. If I can just get the file to convert to a Word.doc
I'd have it. Any help would be appreciated.

Thanks in advance,
BZ
Jul 19 '05 #1
0 2684

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doc Wally | last post by:
Dear Colleagues: To begin with I am not a programmer. In fact, I just got all excited because I was able to create my very first .vbs script that actually worked - not that I actually coded...
163
by: Shiperton Henethe | last post by:
Hi Know any good utilities to help me strip out the tags that Microsoft Excel 2002 leaved behind when you try and export an HTML format file? This is driving me NUTS. And really makes me...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
4
Sheepman
by: Sheepman | last post by:
My quest, to put 100 random numbers in ten rows of ten. Then output the same to the screen and a file. My screen output is working,yeah! Text file, not so much. The data is getting there but not...
2
by: dmk | last post by:
Hi Again, I am reading a document into a page and then displaying it as source code (this is for an assignment.) I feel that the output that I am getting is a little hard to read, and want to...
3
by: zayyaz | last post by:
I am using an excel sheet to keep track of the finances of my afterschool program. Each week I am creating an invoice for the families that have a different balance, outputing from the excel file to...
9
by: Odysseus | last post by:
Hello, group: I've just begun some introductory tutorials in Python. Taking off from the "word play" exercise at <http://www.greenteapress.com/thinkpython/html/book010.html#toc96> I've written...
10
by: sara | last post by:
Hi - I have a report that is 14 columnar sub-reports (Line up: Position- holders in each of our 14 locations - Manager, Assistant Manager, Receiving, Office, etc). I output directly to PDF...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.