473,394 Members | 1,951 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,394 software developers and data experts.

send a word document through POST using VB .net 2005

Hey guys, I have a question for you,
I have a setup where I'm sending files through the POST to a php web page, I
read the file contents, put that file contents as text into the POST string,
and send it on it's way.

it works perfectly for text files. However, I can't open a word document
like a text file and have it give me the result I need. I'm looking for a
way to just open a word document and get all the values in it like you would
if you opened it with notepad. any ideas? or any suggestions on how to
better send a non-text file through post? Thanks!
Jan 6 '06 #1
10 8911
You need to perform a http upload, whether from an asp.net page, or from an
application. PHP knows how to accept form data with attachments and word
docs need to go over the wire as complete files or you will lsoe all the
formatting. If you dont need it preserved as a word doc, use word
automation to open the doc and read its contents.

--
Regards

John Timney
Microsoft MVP

"Aj Blosser" <Aj*******@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
Hey guys, I have a question for you,
I have a setup where I'm sending files through the POST to a php web page,
I
read the file contents, put that file contents as text into the POST
string,
and send it on it's way.

it works perfectly for text files. However, I can't open a word document
like a text file and have it give me the result I need. I'm looking for a
way to just open a word document and get all the values in it like you
would
if you opened it with notepad. any ideas? or any suggestions on how to
better send a non-text file through post? Thanks!

Jan 6 '06 #2
Right, but is there some kind of upload function? I need to do this from an
application as It's part of an MS word addin. as of now I'm using
MSXML2.ServerXMLHTTP to send the POST request, but what I can't figure out is
how to send the file over. I'm assuming that the "body" parameter of the
send method is for the POST query string, this might be my problem, but I
can't find any specifics on this.

"John Timney ( MVP )" wrote:
You need to perform a http upload, whether from an asp.net page, or from an
application. PHP knows how to accept form data with attachments and word
docs need to go over the wire as complete files or you will lsoe all the
formatting. If you dont need it preserved as a word doc, use word
automation to open the doc and read its contents.

--
Regards

John Timney
Microsoft MVP

"Aj Blosser" <Aj*******@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
Hey guys, I have a question for you,
I have a setup where I'm sending files through the POST to a php web page,
I
read the file contents, put that file contents as text into the POST
string,
and send it on it's way.

it works perfectly for text files. However, I can't open a word document
like a text file and have it give me the result I need. I'm looking for a
way to just open a word document and get all the values in it like you
would
if you opened it with notepad. any ideas? or any suggestions on how to
better send a non-text file through post? Thanks!


Jan 6 '06 #3
Here's the code I'm using btw:

Dim http As New MSXML2.ServerXMLHTTP

'Create XMLHTTP/ServerXMLHTTP/WinHttprequest object
'You can use any of these three objects.
' http = CreateObject("WinHttp.WinHttprequest.5")
' http = CreateObject("MSXML2.XMLHTTP")
http = CreateObject("MSXML2.ServerXMLHTTP")

'Open URL As POST request
http.open("POST", URL, False)

'Set Content-Type header
http.setRequestHeader("Content-Type", "multipart/form-data;
boundary=" + Boundary)
http.setRequestHeader("name", "datafile")
http.setRequestHeader("filename", "ocxtest.txt")
http.setRequestHeader("Content-Disposition",
"attachment;filename=mitchell-pres.zip")

'Send the form data To URL As POST binary request

Dim d As String


d = "--" + Boundary + vbCrLf + "Content-Disposition: form-data;
name='file';" + " filename=OCXTEST.DOC " + vbCrLf + "Content-Type:
multipart/form-data;" + vbCrLf + vbCrLf
' http.send(d)
http.send(FormData)

d = vbCrLf + "--" + Boundary + "--" + vbCrLf
'http.send(d)
MsgBox(FormData)


'Get a result of the script which has received upload
WinHTTPPostRequest = http.responseText
MsgBox(http.responseText)
Jan 6 '06 #4
take a read of this - you may be able to get it working from within word.
You should almost certainly be able to use the IE object example from within
word.

http://www.motobit.com/tips/detpg_post-binary-data-url/

--
Regards

John Timney
Microsoft MVP

"Aj Blosser" <Aj*******@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
Right, but is there some kind of upload function? I need to do this from
an
application as It's part of an MS word addin. as of now I'm using
MSXML2.ServerXMLHTTP to send the POST request, but what I can't figure out
is
how to send the file over. I'm assuming that the "body" parameter of the
send method is for the POST query string, this might be my problem, but I
can't find any specifics on this.

"John Timney ( MVP )" wrote:
You need to perform a http upload, whether from an asp.net page, or from
an
application. PHP knows how to accept form data with attachments and word
docs need to go over the wire as complete files or you will lsoe all the
formatting. If you dont need it preserved as a word doc, use word
automation to open the doc and read its contents.

--
Regards

John Timney
Microsoft MVP

"Aj Blosser" <Aj*******@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
> Hey guys, I have a question for you,
> I have a setup where I'm sending files through the POST to a php web
> page,
> I
> read the file contents, put that file contents as text into the POST
> string,
> and send it on it's way.
>
> it works perfectly for text files. However, I can't open a word
> document
> like a text file and have it give me the result I need. I'm looking
> for a
> way to just open a word document and get all the values in it like you
> would
> if you opened it with notepad. any ideas? or any suggestions on how to
> better send a non-text file through post? Thanks!


Jan 6 '06 #5
Hello Aj,
Hey guys, I have a question for you,
I have a setup where I'm sending files through the POST to a php web
page, I
read the file contents, put that file contents as text into the POST
string,
and send it on it's way.
it works perfectly for text files. However, I can't open a word
document like a text file and have it give me the result I need. I'm
looking for a way to just open a word document and get all the values
in it like you would if you opened it with notepad. any ideas? or any
suggestions on how to better send a non-text file through post?


There's really no difference between text and binary data (which is a false
notion anyway): Open the file using a FileStream, load its contents to a
buffer in memory (e.g. a MemoryStream), and post these bytes. If buffernig
in memory isn't required, you can copy the bytes read from the FileStream
directly to your NetworkStream.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jan 7 '06 #6
See, the problem is, when I read the word doc into a filestream,
all I get out of that is:

using .readline 5 or 6 ascii characters. ?'s and blocks.
using .read I get close to the right filesize, but it's all numbers
and using .basestream.readbyte it locks up and stalls on me.

any suggestions?

"Joerg Jooss" wrote:
Hello Aj,
Hey guys, I have a question for you,
I have a setup where I'm sending files through the POST to a php web
page, I
read the file contents, put that file contents as text into the POST
string,
and send it on it's way.
it works perfectly for text files. However, I can't open a word
document like a text file and have it give me the result I need. I'm
looking for a way to just open a word document and get all the values
in it like you would if you opened it with notepad. any ideas? or any
suggestions on how to better send a non-text file through post?


There's really no difference between text and binary data (which is a false
notion anyway): Open the file using a FileStream, load its contents to a
buffer in memory (e.g. a MemoryStream), and post these bytes. If buffernig
in memory isn't required, you can copy the bytes read from the FileStream
directly to your NetworkStream.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Jan 7 '06 #7
Hello Aj,
See, the problem is, when I read the word doc into a filestream,
all I get out of that is:
using .readline 5 or 6 ascii characters. ?'s and blocks.
Readline() is a StreamReader method. That won't work, as Word files are binary
content.
using .read I get close to the right filesize, but it's all numbers


*Bytes*. But that's what you want! You cannot get a meaningful string representation
of Word document.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jan 7 '06 #8
I guess that's where my confusion is.

So is what your saying, I need to find a way in PHP to convert the bytes to
binary?

"Joerg Jooss" wrote:
Hello Aj,
See, the problem is, when I read the word doc into a filestream,
all I get out of that is:
using .readline 5 or 6 ascii characters. ?'s and blocks.


Readline() is a StreamReader method. That won't work, as Word files are binary
content.
using .read I get close to the right filesize, but it's all numbers


*Bytes*. But that's what you want! You cannot get a meaningful string representation
of Word document.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Jan 7 '06 #9
Hello Aj,
I guess that's where my confusion is.

So is what your saying, I need to find a way in PHP to convert the
bytes to binary?


No, the bytes *are* binary. Just save them in your PHP application to disk
or whatever you need to do.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Jan 7 '06 #10
That's what I've been doing, but when I save it as a word doc, and try to
open it up in word, I just get all the bytes as numbers.

Also, if I open a word doc up in note pad pre-sending it has a lot more than
just numbers in it. The word doc that gets sent, ONLY has numbers in it.

"Joerg Jooss" wrote:
Hello Aj,
I guess that's where my confusion is.

So is what your saying, I need to find a way in PHP to convert the
bytes to binary?


No, the bytes *are* binary. Just save them in your PHP application to disk
or whatever you need to do.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Jan 7 '06 #11

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

Similar topics

15
by: Caversham | last post by:
Is there any macro / other tool - free or commercial - that can split long Word docs into multiple XHTML pages? Any comments on the quality/effectiveness of suitable products also welcomed.
5
by: mark kurten | last post by:
i have a requirement to send a soap message to a web service. i'm familiar with the soap toolkit using vb. i need to generate a xml document which i think i can do, but i don't know how to...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
10
by: Neil | last post by:
An article at http://news.com.com/2100-1012-991694.html?tag=fd_top states: "XML would allow easier interchange of data generated in Office documents with back-end systems or existing Web...
7
by: Andy Davis | last post by:
I have a table of data in Access 2002 which is used as the source table for a mail merge document using Word 2002 on my clients PC. The data is transferred OK but I've noticed that any dates which...
12
by: Rob Nicholson | last post by:
We've implemented functionality to allow a user to download a document (any document type) from the IIS server using the following code: Response.Clear() Response.ContentType =...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
4
by: =?Utf-8?B?QXJ0?= | last post by:
Hello, I saw this posting and it is the closest place to ask this question. I am simply trying to create a Word document from a VB application I am wrting with Visual Studio 2005. I cut a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.