C# 使用C从asp.net中的联机路径保存文件#

C# 使用C从asp.net中的联机路径保存文件#,c#,asp.net,C#,Asp.net,我需要通过asp.net中的C#从给定路径保存文件 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

我需要通过asp.net中的C#从给定路径保存文件

 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);
    }
}

是的,还有?它不起作用吗?你有错误吗?如果是:那是什么错误?我想我需要先创建fileUpload控件