read and write file

  • Thread starter Thread starter Yahya
  • Start date Start date
Y

Yahya

Dear Sirs,

I would like to copy a file from an http (http://...x.doc) address to a
local address (c:\x.doc). How can I do this?

Regards,
Yahya
 
Hi Yahya,

The simplest way is using WebClient.DownloadFile

WebClient wc = new WebClient();
wc.DownloadFile("http://...x.doc", "c:\\x.doc");
 
Yahya said:
I tried it and I am receiving the attached error. Why could this be
happening?

The file you attempt to download is password protected. The code below will
show you how to pass credentials in a web request:

\\\
Imports System.IO
Imports System.Net
..
..
..
Dim wrq As WebRequest = _
WebRequest.Create("https://example.org/shop/order.jsp")
wrq.Credentials = New NetworkCredential("username", "password")
Dim wrp As WebResponse = wrq.GetResponse()
Dim sr As New StreamReader(wrp.GetResponseStream())
MessageBox.Show(sr.ReadToEnd())
sr.Close()
wrp.Close()
///

Replace the URL, "username" and "password" with appropriate values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top