初始上传后上传其他文件
本文关键字:文件 其他 | 更新日期: 2023-09-27 17:56:14
我有一个接受.HTML文件格式的上传脚本。 如果HTML文本包含<img>
标签,我需要将这些图像文件从用户硬盘驱动器上传到服务器。 我正在尝试思考解决此问题的最佳方法。
我正在使用 HTMLAgilityPack 在 HTML 中搜索 img 标签:
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);
}
}
在循环中找到每个图像文件后,如何上传它们?
您可以使用system.network.webclient下载并上传文件,如下所示:
Dim b() As Byte
b = client.DownloadData(URL)
client.Credentials = New NetworkCredential(username, password, domain.com)
client.UploadData("ftp://domain.com/filename.ext", b)