1

I am new to CefSharp and trying to get it to handle downloads. I have implemented IDownloadHandler and it's downloading just how I want to a temp directory. However, after download I try to do more with the file, but it seems it's downloaded with no permissions whatsoever, so it gives me access denied when I try to do anything with it (in this case unpack the zip file).

I can go view the file through File Explorer and I get the message in the security tab 'No groups or users have permission to access this object...'. If I add myself as a user it's fine, but without doing that I can't do anything with the file.

So how do you download something and make it accessible to use?

Here is my download handler class:

class CefDownloadHandler : IDownloadHandler
{
    public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
    {
        Debug.WriteLine("Before Download");

        callback.Continue(Path.Combine(Path.GetTempPath(), downloadItem.SuggestedFileName), false);
    }

    public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
    {
        if (downloadItem.IsComplete)
        {
            new FileInfo(downloadItem.FullPath).SetAccessControl(new System.Security.AccessControl.FileSecurity())
            CoreApp.StartContentLoad(downloadItem.FullPath, downloadItem.Url);
        }

    }
}

EDIT

This seems to be related to the location after more testing. I was originally saving to the temp directory using Path.GetTempPath() and having this issue. Just to test I modifed to use a folder under %appdata% and it saves with normal permissions and works. I have access and permissions to the temp folder so I'm not sure why but it seems to be related to that...

sfaust
  • 2,089
  • 28
  • 54
  • 1
    What version are you using? Does the problem reproduce if you apply your `DownloadHandler` to https://github.com/cefsharp/CefSharp.MinimalExample/tree/cefsharp/69 (branch using the latest `-pre` release). I'm not seeing any problems, nor have I had other reports of problems. – amaitland Nov 07 '18 at 10:02
  • 1
    Could be one of those cases you need an `app.manifest` with `compatibility` entries, see https://github.com/cefsharp/CefSharp.MinimalExample/blob/master/CefSharp.MinimalExample.WinForms/app.manifest#L43 – amaitland Nov 07 '18 at 10:05
  • I'm using version 57 and unfortunately I have to do so. The program is an add-in to another program that uses CEF 57 so I have to align with that... – sfaust Nov 07 '18 at 16:48
  • I don't think I can do a manifest when it's an add-in to another program can I? Sorry I should have mentioned that part at first. However, I am running this as a standalone application for testing the base system but in final form it will have to be embedded in the other app that I don't have control of... – sfaust Nov 07 '18 at 16:50

1 Answers1

0

you should not save directly on ApplicationData folder, as mentioned here.

yoni
  • 191
  • 1
  • 2
  • 12