By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

send a word document through POST using VB .net 2005

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.