views:

328

answers:

3

Hi,

I'm building an application where I need to use a saveFileDialog. The problem is that I want to restrict the users from using some parts of the saveFileDialog (e.g. I don't want them to edit the name of the file). I've heard that it's very difficult to do this using Windows forms SaveAsDialog. Do you know how to do this in native code? Do you have a full undestandable example (I need the whole example, since I've never used Windows API)?

PS. I really need to use the saveFileDialog to keep UI consistency.

A: 

create your own savefiledialog (create from scratch)

Just create a form that looks almost the same as a savefiledialog but with a label for name instead of textbox

PoweRoy
The SaveFileDialog cannot be inherited.
ThePower
SaveFileDialog isn't form, but just an facade over unmanaged API.
Yossarian
Neither being a final class nor being a facade over an API prevents someone from writing a custom dialog box that looks and acts like a standard component. This is a good answer.
Rob Kennedy
thanks rob, the first part is indeed not correct
PoweRoy
Creating your own SaveFileDialog is a lot of work and not really a practical solution; we've done it for Creative Docs .NET (http://www.creativedocs.net), but the results are not satisfactory; the richness of the shell is almost impossible to reproduce, less so if you want to be cross-Windows-version compatible.
Pierre
+3  A: 

If the file name is fixed and the user shall only navigate to an alternate location simply use the FolderBrowserDialog instead. IMHO, this would be consistent, too.

Frank Bollack
I don't really see where you've answered the question of how to disable parts of the dialog. If you want to deny the premise of the question, then leave a comment, not an answer.
Rob Kennedy
As the question is also about UI consistency, I don't think I deny the premise of the question.Consitency from my point of view is using the appropriate tool for a task, not some other thing that needs to be bent to fit.
Frank Bollack
@incredible_Honk, seems Mr Kennedy has a stock comment that he likes to paste in without contributing to the answer.
Lazarus
Honk, `FolderBrowserDialog` would indeed be a good suggestion if Bluetiger had asked for a way to restrict people from changing file names in a save dialog, but that's not what he or she asked for. The question was about how to modify the behavior of the save dialog, of which **one example** was to restrict the file name. You solved the specific example, but not the general question.
Rob Kennedy
Lazarus, it's not a stock comment, merely a one I felt applied to two answers here, so I copied and pasted it *once*. Two data points don't make a trend. And since what I had to say was not an answer to the question, I posted comments. That's what comments are *for*. Just because I don't have an answer of my own doesn't mean I can't say that others' answers are of low quality.
Rob Kennedy
Rob, thanks for your comments and in the name of Bluetiger also thanks for your commitment, but if he had a problem with the answer, he could comment for him self or just down vote the answer.From the posted qusetion I couldn't read that restricting the file name is just one example. I read it as "thats the thing I want to achive". And as long as the poster doesn't give more information about his restriction to a SaveFile dialog you can hardly say my answer misses the target.
Frank Bollack
Rob, fair enough. It was unfair to tar and feather you based on a two instances.
Lazarus
+3  A: 

If you really want to use the common save file dialog, but want to make the file name read-only you will probably have to call to native code. You can provide a lot of customizations using a hook. You will have to study some Windows API's:

Customizing Common Dialog Boxes

Open and Save As Dialog Boxes

GetSaveFileName Function (Using GetSaveFileName from managed code)

OPENFILENAME Structure (Using OPENFILENAME from managed code)

I haven't been doing old-style Windows API for a long time so the following idea is just that: an idea. Perhaps you can create a hook and in WM_INITDIALOG you can find the edit control with the file name. It seems to be named edt1. Perhaps you can then modify the windows style of the control to make it read-only.

But maybe some of the other answers provided here are better alternatives than hacking the save as dialog box.

Martin Liversage