364,085 Members | 5378 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

send a word document through POST using VB .net 2005

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


John Timney \( MVP \)
P: n/a
John Timney \( MVP \)
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" <AjBlosser@discussions.microsoft.com> wrote in message
news:917D5B43-61AB-40F5-9054-B8A4DD9FF8AC@microsoft.com...[color=blue]
> 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![/color]


Jan 6 '06 #2

Aj Blosser
P: n/a
Aj Blosser
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:
[color=blue]
> 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" <AjBlosser@discussions.microsoft.com> wrote in message
> news:917D5B43-61AB-40F5-9054-B8A4DD9FF8AC@microsoft.com...[color=green]
> > 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![/color]
>
>
>[/color]
Jan 6 '06 #3

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

John Timney \( MVP \)
P: n/a
John Timney \( MVP \)
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" <AjBlosser@discussions.microsoft.com> wrote in message
news:C1D380DD-D57F-48D2-ABCD-7B4D350EA8F7@microsoft.com...[color=blue]
> 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:
>[color=green]
>> 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" <AjBlosser@discussions.microsoft.com> wrote in message
>> news:917D5B43-61AB-40F5-9054-B8A4DD9FF8AC@microsoft.com...[color=darkred]
>> > 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![/color]
>>
>>
>>[/color][/color]


Jan 6 '06 #5

Joerg Jooss
P: n/a
Joerg Jooss
Hello Aj,
[color=blue]
> 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?[/color]

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
news-reply@joergjooss.de


Jan 7 '06 #6

Aj Blosser
P: n/a
Aj Blosser
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:
[color=blue]
> Hello Aj,
>[color=green]
> > 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?[/color]
>
> 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
> news-reply@joergjooss.de
>
>
>[/color]
Jan 7 '06 #7

Joerg Jooss
P: n/a
Joerg Jooss
Hello Aj,
[color=blue]
> 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.[/color]

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

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

Cheers,
--
Joerg Jooss
news-reply@joergjooss.de


Jan 7 '06 #8

Aj Blosser
P: n/a
Aj Blosser
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:
[color=blue]
> Hello Aj,
>[color=green]
> > 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.[/color]
>
> Readline() is a StreamReader method. That won't work, as Word files are binary
> content.
>[color=green]
> > using .read I get close to the right filesize, but it's all numbers[/color]
>
> *Bytes*. But that's what you want! You cannot get a meaningful string representation
> of Word document.
>
> Cheers,
> --
> Joerg Jooss
> news-reply@joergjooss.de
>
>
>[/color]
Jan 7 '06 #9

Joerg Jooss
P: n/a
Joerg Jooss
Hello Aj,
[color=blue]
> 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?[/color]

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

Cheers,
--
Joerg Jooss
news-reply@joergjooss.de


Jan 7 '06 #10

Aj Blosser
P: n/a
Aj Blosser
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:
[color=blue]
> Hello Aj,
>[color=green]
> > 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?[/color]
>
> No, the bytes *are* binary. Just save them in your PHP application to disk
> or whatever you need to do.
>
> Cheers,
> --
> Joerg Jooss
> news-reply@joergjooss.de
>
>
>[/color]
Jan 7 '06 #11

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework