0

I am attempting to download a file from another IIS site on my local machine. I have my main website that is trying to download from another public site that contains a few files that the user will be able to download.

[HttpGet]
public ActionResult DownloadMyPrintManagerInstaller()
{
    bool success;
    try
    {
        using (var client = new WebClient())
        {
            client.DownloadFile(new Uri("http://localhost:182//MyPrintInstaller.exe"), "MyPrintManager.exe");
        }
        success = true;
    }
    catch (Exception)
    {
        success = false;
    }

    return Json(new { Success = success }, JsonRequestBehavior.AllowGet);
}

For some reason, it is attempting to download the file from C:\windows\system32\inetsrv\MyPrintManager.exe? Does anyone know how I can avoid it from pointing to that directory? Do I need to modify my code or my IIS configuration?

My virtual directory for this site is a folder sitting on my C: drive, and the file I actually want to download is in that directory.

gwin003
  • 7,432
  • 5
  • 38
  • 59

2 Answers2

4

No, it's attempting to save the file to C:\windows\system32\inetsrv\MyPrintManager.exe.

That's because C:\windows\system32\inetsrv is the working directory for your process, and you've just given a relative filename.

Specify an absolute filename which says exactly where you want the file to be stored, and it should be fine.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • So I need to specify the second param as `C:\MyPrintManager.exe` or something like that? edit:tagging isnt working well for me right now – gwin003 May 10 '13 at 15:01
  • @gwin003: Something like that - but probably not directly in the root of your C drive... – Jon Skeet May 10 '13 at 15:17
  • I haven't found an appropriate directory to download to yet, I am getting the same error message. Any idea what directory I cam download to without using the client username? Or is there a way I can tell it to download to the default download directory? – gwin003 May 10 '13 at 17:02
  • All the examples I have seen seem to have no problems downloading to the C drive. See: http://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.80).aspx – gwin003 May 10 '13 at 17:04
  • 1
    @gwin003: You're running a service, which will have restricted access. You should probably create a dedicated directory for this, and give it the right permissions. – Jon Skeet May 10 '13 at 17:30
  • Thanks, You got me on the right path. I'll need to figure the rest out on my own. – gwin003 May 10 '13 at 17:53
-1
WebClient web = new WebClient();
string url = "http://.../FILENAME.jpg";
web.DownloadFile(new Uri(url), "C:/FILENAME.jpg");
pinckerman
  • 4,115
  • 6
  • 33
  • 42
  • This doesnt attempt to answer the permission question that the OP is looking for. In fact, he's got this exact same code functionality in the body of his question. – crthompson Nov 08 '13 at 00:03