1

I have an upload script that accepts a .HTML file format. If the HTML text contains <img> tags, I need to upload those image files to the server from the users hard drive. I'm trying to think of the best way to approach this.

I am using HTMLAgilityPack to search HTML for img tags:

 List<string> allTags = new List<string>();

            HtmlDocument doc = new HtmlDocument();
            doc.Load(@"C:\Users\Mike\Documents\website.htm");
            HtmlNodeCollection linkNodes = doc.DocumentNode.SelectNodes("//img");

            // Run only if there are img in the document.
            if (linkNodes != null)
            {
                foreach (HtmlNode linkNode in linkNodes)
                {
                    HtmlAttribute attrib = linkNode.Attributes["src"];
                    string attribString = attrib.Value.ToString();

                    allTags.Add(attribString);
                }
            }

How can I upload each of the image files once they are found in the loop?

user547794
  • 14,263
  • 36
  • 103
  • 152

1 Answers1

3

You can download and upload the file with the system.network.webclient, something like this:

Dim b() As Byte

b = client.DownloadData(URL)
client.Credentials = New NetworkCredential(username, password, domain.com)
client.UploadData("ftp://domain.com/filename.ext", b)
xpda
  • 15,585
  • 8
  • 51
  • 82