locked
Can't download file from URL RRS feed

  • Question

  • So,

    I want to download a file using this:

    updateUri is a string

    Client.DownloadFileAsync(new Uri(updateUri), "setup.msi");
    

    However, it works during debugging, downloads so good that it feels too legit.

    But when deplyoing it to the folder it belongs.. It doesn't download.

    Been trying with full paths, app path.. And so on...

    Anyone able to help me?

    -Vincent

    Thursday, February 5, 2015 7:50 PM

Answers

  • You can't just download files to there, it won't work.

    Open up programme files, pick a folder.

    Right click and choose file new >

    If I do that on my 7-zip folder on this win 8.1 machine I see one option New Folder and next to it is the shield thing indicates I have to give admin permissions to do this.

    Try editing a config file.

    You can't save it back over the file that's there.

    This is because they tightened up on permissions.

    You can copy files which are already on disk on the machine from a different location into there.

    By coincidence I am currently working on a wpf application which downloads a couple of web pages as files for viewing later in a webbrowser.

    I install using wix.

    I suggest you consider using isolatedstorage for this sort of thing.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/95b5fe48-9fb9-4ed6-a3d3-e011ec90b582/cant-download-file-from-url?forum=csharpgeneral

    Use GetUserStoreForAssembly.

    Do not use other methods - a bunch of them only work in quite specific circumstances.

    When you download the file save it to:

    fname = IsolatedStorageFile.GetUserStoreForAssembly() + "somename.txt";

    It ends up in a bit of  strange folder structure under the user's appdata > isolatedstorage >

    Since appdata is a hidden folder, most users will be totally unaware there is even such a folder to look at. So the chances of anyone messing with it are pretty slim.

    Anyhow... you can do whatever you like there.


    Hope that helps.
    Recent Technet articles: Property List Editing ;   Dynamic XAML

    • Marked as answer by Kristin Xie Friday, February 13, 2015 4:56 AM
    Saturday, February 7, 2015 4:25 PM

All replies

  • Are you changing what kind of network you are downloading from? IE: debug on Ethernet but when deployed users connect with WiFi.

    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums

    Thursday, February 5, 2015 8:29 PM
  • I experimented a bit more regarding my issue, and I found out that the issue only happens in my Program Files.

    I wonder why..

    Thursday, February 5, 2015 8:33 PM
  • I would assume permissions, as Program Files is protected.

    EDIT: Could you install the program under the Program Files, and have the download go to the Program Data directory?


    Mediocre Access 2010 | (Baby) Beginner C Sharp | OK at Active Directory (2012) | Fragmented understanding of DNS/DHCP | Laughable experience with Group Policy | Expert question asker on MSDN Forums


    • Edited by UpTide Thursday, February 5, 2015 9:30 PM
    Thursday, February 5, 2015 8:37 PM
  • Hey,

    I tried that out and gives me nothing.

    btw, I have an event for when the DL is done, and that shoots directly with this error. Like if the file would be done, but no file in the targetpath.

    Thursday, February 5, 2015 9:23 PM
  • Hi Vincent,

    >> I have an event for when the DL is done, and that shoots directly with this error

    Could you share us this error message?

    >>Like if the file would be done, but no file in the targetpath.

    I am wondering if you deploy this program at your developing folder, could it work correctly?


    Help each other

    Friday, February 6, 2015 10:35 AM
  • private void buttonDownloadFile_Click(object sender, EventArgs e)
    {
        string url = @"http://www.thereforesystems.com/wp-content/uploads/2008/08/image35.png";
        // Create an instance of WebClient
        WebClient client = new WebClient();
        // Hookup DownloadFileCompleted Event
        client.DownloadFileCompleted +=    new AsyncCompletedEventHandler(client_DownloadFileCompleted);
    
        // Start the download and copy the file to c:\temp
        client.DownloadFileAsync(new Uri(url), @"c:\temp\image35.png");
     }
    
    void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        MessageBox.Show("File downloaded");
    }


    Mark as answer or vote as helpful if you find it useful | Ammar Zaied [MCP]

    Friday, February 6, 2015 1:34 PM
  • Hi Vincent,

    >>However, it works during debugging, downloads so good that it feels too legit.
    >>But when deplyoing it to the folder it belongs.. It doesn't download.

    I am not sure if I understand your issue correctly. You mean your program works during debugging, but not working after deploying. Am I right? I am wondering whether you used the same “updateUri”. If it is not the same, I would recommend you use the same “updateUri” to test. If it is the same string, I am wondering how and where you deployed your project. Your project might be broken while delploying.

    >> I found out that the issue only happens in my Program Files.

    What did you mean with this issue? Did it mean you could download file to any other folders instead of Program Files. If so, I would be wondering whether you have the permission to create file in the “Program Files”.

    >> I have an event for when the DL is done, and that shoots directly with this error

    Could you share us the error message? Could i assume that you debugged it correctly,but after you deploying it, it run into error?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Saturday, February 7, 2015 7:08 AM
  • Hi guys,

    So summarise my problem:

    • I am using Wix to 'deploy' my WPF app, meaning that my EXE and all it belongings installs to the folder of my choice.
    • The WPF app has an built in downloader which downloads updates and so on.
    • With the downloader, when the EXE file is in program files (x86) etc, the file doesn't download. - Which then directly shoots the "downloadCompleted" event, no error.
    • Placing it outside the Program files folder works.
    • I have tried to set permissions in my folder but seems like it doesn't do anything..

    Saturday, February 7, 2015 4:00 PM
  • You can't just download files to there, it won't work.

    Open up programme files, pick a folder.

    Right click and choose file new >

    If I do that on my 7-zip folder on this win 8.1 machine I see one option New Folder and next to it is the shield thing indicates I have to give admin permissions to do this.

    Try editing a config file.

    You can't save it back over the file that's there.

    This is because they tightened up on permissions.

    You can copy files which are already on disk on the machine from a different location into there.

    By coincidence I am currently working on a wpf application which downloads a couple of web pages as files for viewing later in a webbrowser.

    I install using wix.

    I suggest you consider using isolatedstorage for this sort of thing.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/95b5fe48-9fb9-4ed6-a3d3-e011ec90b582/cant-download-file-from-url?forum=csharpgeneral

    Use GetUserStoreForAssembly.

    Do not use other methods - a bunch of them only work in quite specific circumstances.

    When you download the file save it to:

    fname = IsolatedStorageFile.GetUserStoreForAssembly() + "somename.txt";

    It ends up in a bit of  strange folder structure under the user's appdata > isolatedstorage >

    Since appdata is a hidden folder, most users will be totally unaware there is even such a folder to look at. So the chances of anyone messing with it are pretty slim.

    Anyhow... you can do whatever you like there.


    Hope that helps.
    Recent Technet articles: Property List Editing ;   Dynamic XAML

    • Marked as answer by Kristin Xie Friday, February 13, 2015 4:56 AM
    Saturday, February 7, 2015 4:25 PM