使用c#从asp.net的在线路径中保存文件
本文关键字:在线 路径 保存文件 net asp 使用 | 更新日期: 2023-09-27 17:50:24
我需要通过c#在asp.net中保存给定路径下的文件
FileUpload fileToUpload =new FileUpload();
string path = "http://maps.googleapis.com/maps/api/staticmap?center=34.08326024943277,74.79841209948063&zoom=21&size=550x450&maptype=roadmap&sensor=true";
string FileName = "mirImg" + Guid.NewGuid().ToString();
fileToUpload.SaveAs("~/saveImages/" + FileName);
可以这样做:
using (WebClient Client = new WebClient ())
{
Client.DownloadFile(path, FileName);
}
您可以将所有数据以字节形式获取,然后写入文件。
static void Main(string[] args)
{
using(WebClient client = new WebClient())
{
byte[] data = client.DownloadData("http://maps.googleapis.com/maps/api/staticmap?center=34.08326024943277,74.79841209948063&zoom=21&size=550x450&maptype=roadmap&sensor=true");
File.WriteAllBytes(@"D:'file.jpg", data);
}
}