C#中怎么下载URL上的文件?

Kusk 2006-03-02 11:41:55
例如URL:
http://192.168.32.51/files/abc.txt

如何把它下载(打开)?
手头没有书上网运气不好搜不到(太菜了)~~~·······
...全文
1018 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kusk 2006-03-07
  • 打赏
  • 举报
回复
谢谢!
lidong6 2006-03-03
  • 打赏
  • 举报
回复
webclient.download
lovvver 2006-03-03
  • 打赏
  • 举报
回复
string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;

WebClient myWebClient = new WebClient();
myStringWebResource = remoteUri + fileName;
myWebClient.DownloadFile(myStringWebResource,fileName);

去掉注释看得清楚点,哈哈
ClientDC 2006-03-03
  • 打赏
  • 举报
回复
WebClient Client=new WebClient();
Client.DownloadFile("http://192.168.32.51/files/abc.txt","d:\abc.txt");
Hatrim 2006-03-03
  • 打赏
  • 举报
回复
可以用WebClient来下载,下载下来后用Process的start打开就可以了
califord 2006-03-03
  • 打赏
  • 举报
回复
不懂楼上说的
saucer 2006-03-03
  • 打赏
  • 举报
回复
use System.Net.WebClient class or System.Net.HttpWebRequest/System.Net.HttpWebResponse class

for example, for WebClient's DownloadFile method documentation

string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource,fileName);
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧