Click here to Skip to main content
14,636,013 members
Rate this:
Please Sign up or sign in to vote.
See more:
I would like to make a SaveFileDialog box with a CheckBox option for read only or not

I have this code for a event button

private void button1_Click(object sender, EventArgs e)
   {
     Stream myStream;
     SaveFileDialog saveFileDialog1 = new SaveFileDialog();

     saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
     saveFileDialog1.FilterIndex = 2;
     saveFileDialog1.RestoreDirectory = true;


     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
       if ((myStream = saveFileDialog1.OpenFile()) != null)
       {
         // Code to write the stream goes here.
         myStream.Close();
       }
     }
   }
Posted
Updated 12-Sep-11 20:14pm
v2
Comments
Suresh Suthar 13-Sep-11 2:15am
   
Please explain a bit more.
Prerak Patel 13-Sep-11 2:17am
   
ReadOnly option in SaveFileDialog?! Does it make sense?
Abraham Thomsen 13-Sep-11 5:23am
   
No it doesn't for real. But i Want to put a checkbox option for to save as readonly or not in saveFileDialog box.
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can use read only option in OpenFileDialog, not SaveFileDialog.
http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.readonlychecked.aspx[^]
   
Comments
Mehdi Gholam 13-Sep-11 2:20am
   
HeHe, just posted the same, 5!
Prerak Patel 13-Sep-11 3:19am
   
Thanks :)
Rate this:
Please Sign up or sign in to vote.

Solution 1

SaveFileDialog has no ReadOnly and it makes no sense as you want to save a file, and you can't write to a read-only file.

You need to use the OpenFileDialog which has a ShowReadOnly property which you can set to True.
   
Comments
Prerak Patel 13-Sep-11 3:18am
   
OP:
Hej Mehdi

Yes i understand you. but will it be possible to show the showReadOnly Option in SaveFileDialog by any means.
Mehdi Gholam 13-Sep-11 3:29am
   
arrrgh!
Rate this:
Please Sign up or sign in to vote.

Solution 4

So what could be the solution for this ? Making my Own SaveFileDialog
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

I am also looking for this solution.  I don't think the other posters are understanding the need here.   I want the user to have an option to save their file as read-only.  I can add a check box for this in my main application, but it would be more elegant if I could just display a check box in the file save dialog.

My solution was just to convert my "Save..." button in my main program be a drop down menu button.  If the user wants to save normally, then they click the button as normal.   If they want to save as read-only, then they select the "Save As Read-only" option in the drop down.  If that option is selected, then I make the file read-only in code, after it is saved.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Hej Mehdi

Yes i understand you. but will it be possible to show the showReadOnly Option in SaveFileDialog by any means.
   
Comments
Prerak Patel 13-Sep-11 3:18am
   
You should add this as comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100