How to grab attachment from a list of given URL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I try to design a window application to grab attachment from a list of given
URL and save them to a user difined folder on their local drive.

The list of URL for me to grab attachment will be saved in text file format.
The URL's might be ending with attachment file types: .jpg, .gif, pdf...also,
they might be just an ASP page.

I would like to have number of downloaded attachment displayed on the form
while the program is downloading, as well as a pictureBox displaying each
successfully downloaded picture (except .ptf).

Any good ideas for me to do so in C# in VS 2005? Is there any example code
that I could use?

Thanks,

Sophie
 
Sophie,

This is thousand times done with the Webbrowswer, however I think that
everybody sees this as a kind of personal chalenge. If you search on
Internet you can find a lot of it. You need it in combination with MSHTML to
get the Anchor and Image tags and related information.

You cannot get an ASP page doing this, only the HTML results of that.
Getting ASP pages is hacking.

Cor
 
Thank you. I will look for the infomation for "MSHTML to get the Anchor and
Image tags" on the web.

Sophie
 
Uri uri = new Uri("http://cdx.xceligent.com/Attachments/034/826034.jpg");
System.Net.WebRequest request = System.Net.WebRequest.Create(uri);
using (System.Net.WebResponse response = request.GetResponse())
{
using (System.IO.Stream stream = response.GetResponseStream())
{
using (System.IO.Stream outputStream = new
System.IO.FileStream(@"c:\out.dat", System.IO.FileMode.Create))
{
byte[] inputBuffer = new byte[Math.Max(1024,
response.ContentLength)];
int bytesRead = 0;
do
{
bytesRead = stream.Read(inputBuffer, 0,
inputBuffer.Length);
if (bytesRead > 0)
{
outputStream.Write(inputBuffer, 0, bytesRead);
}
}
while (bytesRead != 0);
}
}
}
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
 
If you need to parse through the HTML of a rendered web page to extract
links to images, PDF etc. suggest you take a look at Simon Mourier's
HtmlAgilityPack.
Peter
 
Back
Top