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...