473,789 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Wr ite byteArray 'Need to
format
<%Response.Buff er=0 %>
<!--#include file="global.as p" -->

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

Server.ScriptTi meout = 600
Set oUpload = Server.CreateOb ject("asppw.upl oad")
'Set properties first
'oUpload.FileEx tensionList = "txt,gif,jpg,ti f,doc,bmp,xls"
'oUpload.MaxFil eSize = 10 * 1024 * 1024
'oUpload.UserDi skQuota = 20 * 1024 * 1024

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

ChkError "Upload failed:"

Set oFiles = oUpload.Uploade dFileInfo
Set oForm = oUpload.Form

Dim sFileName, lFileLength, byteArray, sDirectory

byteArray = oUpload.GetUplo adedFileBlob("d ocumentFile",sF ileName
,lFileLength )
ChkError "Upload File Blob failed:"

Const adTypeBinary = 1
Const adTypeText = 2

Const adSaveCreateOve rWrite = 2

'Create Stream objects
Dim BinaryStream
Set BinaryStream = CreateObject("A DODB.Stream")
'Specify stream type - we want To save binary data.
BinaryStream.Ty pe = adTypeBinary
'Open the stream And write binary data To the object
BinaryStream.Op en
BinaryStream.Wr ite byteArray
Set fs=CreateObject ("Scripting.Fil eSystemObject")
sOrder = oForm("orderNum ber")
sVersion = oForm("versionN umber")
sExtenstion = oForm("extensio nNumber")
'sRootFolder = Server.mappath( "/Fupload") + "\Upload"

'RemoteHost = Request.ServerV ariables("REMOT E_HOST")

If Request.ServerV ariables("REMOT E_HOST") = "192.168.112.41 " Then
sRootFolder = ("\\it1\ETS2Doc App\ETS Documents")
Else
sRootFolder = ("\\it1\ETS2Doc App\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 strFilePathOnSe rver

strFilePathOnSe rver = sDirectory & "\" & sFileName

If fs.FileExists(s trFilePathOnSer ver) Then
'Response.write "1"
On Error Resume Next
BinaryStream.Lo adFromFile strFilePathOnSe rver
'Response.write strFilePathOnSe rver
If Err.number = 3002 Then
Response.Write( "3002")
' Throw error message in DocumentManager Proxy
Response.End
End If
End If

BinaryStream.Wr ite byteArray 'Need to format

If not Err Then
' Save binary data To disk
'Response.write "2"
BinaryStream.Sa veToFile sDirectory + "\" + sFileName,
adSaveCreateOve rWrite
'Response.write "3"
Response.Write sDirectory & "\" & sFileName '& RemoteHost
End If
Set BinaryStream=No thing

%>
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
FileSystemObjec t 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 "WriteToTex t" 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 2703

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

Similar topics

1
1814
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 it, I took bits and pieces from here and there and boom, it worked.
163
14693
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 hate microsoft with a passion. I literally just want "compact HTML" - ie just the data,
8
3538
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 the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
4
3529
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 formated. If word wrap is off it's a single row. If word wraps on, well ... it wraps. I've considered sizing the notebook window to wrap at the tenth character but I don't think the TA working on his Phd will buy it. Help please! My code for this portion...
2
1226
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 go beyond the scope of the assignment. I want to add formatting (just like what the tags on this forum does. Does anyone know of a simple to implement API for ASP.NET that will allow me to implement this using the method of input below? ...
3
1884
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 a new word file. Everything works except I was wondering if it is possible to format the output within or before the Print # statement. Just typically word formatting things like size, font, underline and what not. If not, is there an alternative...
9
1524
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 a mini-program to tabulate the number of characters in each word in a file. Once the data have been collected in a list, the output is produced by a while loop that steps through it by incrementing an index "i", saying
10
2150
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 (using ConvertReportToPDF from this site - Stephan Lebans) The formatting - Outlines on some fields - do not appear on subreports
12
2181
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 test page and I've managed to bind the usercontrol to a repeater and display some data in the following fashion: <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1"> <ItemTemplate > <uc1:AUserControl runat="server"...
0
9499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10124
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5540
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4078
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.