B
Bruce Zigenfous
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",sFileName
,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
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",sFileName
,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