Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
Download MS Word document through http
neo
Nov 5 2006 10:05 AM
1.7k
Reply
Hi,
I am connecting to a web site using HttpWebRequest, and opening a file url, which is actually a MS word doc.I need to download the same through backend, but the file, on downloading, is getting corrupted.I think the problem is with the
encoding
.Here is how i am doing it:
Dim wReq as HttpWebRequest
Dim wResp as HttpWebResponse
Dim str as String
Dim sr as StreamReader
Dim sw as StreamWriter
wReq = CType(WebRequest.Create(New Uri(strURL)),HttpWebRequest)
wReq.Method = "POST"
wReq.KeepAlive = True
wReq.
Credentials =
New
NetworkCredential(user, passwd, domain)
wReq.ContentType = "application/msword"
wResp = wReq.GetResponse
sr = New
StreamReader(wResp.GetResponseStream, System.Text.Encoding.ASCII)
str = sr.ReadToEnd.Trim
sr.Close()
wResp.Close()
wReq =
Nothing
If
Not
str
Is
Nothing
And
str.Length > 0
Then
sw =
New
StreamWriter(dFolder & filename & "." & "doc"
,
False
)
sw.WriteLine(txt)
sw.Close()
sw =
Nothing
End If
Please note i have to use http Web request only since the site throws up a login page which i am bypassing by
post
ing parameters.
Please help.
Thanks in advance!
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
User control from Radio Button
Simple Help