IFileSaveDialog Save over Read-Only File

Hey Everyone,

I'm new to this forums, and I'm trying to figure out a way to force save over a read-only file when utilizing a IFileSaveDialog. Originally I thought maybe there was an option that I can set via IFileDialog::SetOptions that would bypass the error messagebox that appears when I select a read-only file to save over so that I can then use SetFileAttributes() to remove the read-only attribute from the selected file. Unfortunately, I was not able to find this option, as I tried both FOS_NOTESTFILECREATE and FOS_NOINVALIDATE.

Here is the portion of code that I believe is pertinent to my question. Let me know if you want to see anything else. Appreciate any advice you can provide! Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
IFileSaveDialog* pSaveDialog;
...
...
DWORD dwOptions;
hr = pSaveDialog->GetOptions(&dwOptions);
pSaveDialog->SetOptions(dwOptions | FOS_OVERWRITEPROMPT | FOS_NOTESTFILECREATE | FOS_NOVALIDATE);

hr = pSaveDialog->Show(NULL);
if (SUCCEEDED(hr))
{
  // Grab the shell item that user specified in the save dialog
  IShellItem* pSaveResult = NULL;
  hr = pSaveDialog->GetResult(&pSaveResult);
  if (SUCCEEDED(hr))
  {
    // Extract the full system path from the shell item
    PWSTR pszPathName = NULL;
    hr = pSaveResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPathName);
  }
  if (SUCCEEDED(hr))
  {
    ...
    SetFileAttributes(CW2CT(pszPathName), FILE_ATTRIBUTE_NORMAL);
    ...
  }
}
Last edited on
Topic archived. No new replies allowed.