Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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

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

You can use read only option in OpenFileDialog, not SaveFileDialog.
http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.readonlychecked.aspx[^]
 
Share this answer
 
Comments
Mehdi Gholam 13-Sep-11 2:20am    
HeHe, just posted the same, 5!
Prerak Patel 13-Sep-11 3:19am    
Thanks :)
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.
 
Share this answer
 
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!
So what could be the solution for this ? Making my Own SaveFileDialog
 
Share this answer
 
SQL
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.
 
Share this answer
 
Hej Mehdi

Yes i understand you. but will it be possible to show the showReadOnly Option in SaveFileDialog by any means.
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900