1

I need to save file via C# in asp.net from the given path

 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);
2
  • 4
    Yes - and? Does it not work? Do you get an error? If so: what is that error? Commented Mar 14, 2014 at 8:40
  • i think i need to create fileUpload Control first Commented Mar 14, 2014 at 8:44

2 Answers 2

2

Something like this might work:

using (WebClient Client = new WebClient ())
{
    Client.DownloadFile(path, FileName);
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can get all the data as bytes and then write to a file.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.