|
1) You can't.
2) You can't.
3) You can't.
It's a system dialog, and as such it exposes system facilities. If you want to restrict what it can do that heavily - and you'll annoy a lot of people if you do - then you need to write your own custom "Save As" dialog and use that instead of the system one.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Issues with customizing the built-in WinForms 'FileDialogs ('Open, 'Save) are discussed thoroughly in these CodeProject articles: [^], [^], [^].
I think it's a mistake to try and alter the appearance (the UI) of these Dialogs; Win users are socialized to expect these dialogs to behave in standard ways, and its tricky coding that will entail things like hooking the underlying Window of a Button, using Win API's, etc.
But, you can certainly exert a strong degree of control by creating a custom 'Filter setting restricting the viewed locations.
If you really want total control of where the user can save a file, why not create a ComboBox with all the valid locations in it; idea: use the 'DisplayMember and 'DisplayMember property to display whatever "friendly" name you think is meaningful to the user, and, perhaps, use the 'ValueMember property to hold the DirectoryInfo, or FileInfo you want associated with the "friendly" name. Put the ComboBox in a UserControl and then 'Show/Hide it as necessary.
In short, if you want the user to have fewer options: give them fewer options.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
You can't do any of that stuff with the stock SaveDialog.
But, with all those restrictions, you've pretty much limited the user to entering a filename in a TextBox so why even use a SaveDialog at all?
Also, what if the user accidentally click the SaveAs menu item? How are you giving them a way out without performing the Save operation?
modified 2-Feb-16 9:51am.
|
|
|
|
|
Dave Kreskowiak wrote: Also, what if the use accidentally click SaveAs? How are you giving them a way out without performing the Save operation? With a WinForms SaveFileDialog you can define a 'FileDialog.FileOk EventHandler, in which you can cancel the 'Save operation, and keep the dialog open.
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (saveFileDialog1.FileName == @"C:\Users\SomeUser\Desktop\NoGo.xxx"
|| saveFileDialog1.FileName.ToLower().Contains("forbidden"))
{
e.Cancel = true;
}
} And, when the SaveFileDialog 'returns is closed: of course, you've got another chance to validate and do nothing based on the selected File. And, you've got the power to restrict files viewed by means of the 'Filter Property.
My preference is to never enable showing any kind of Dialog unless the pre-conditions for its valid use are met. So, yeah, that means disabled MenuItems, or Buttons, etc.
Unfortunately, the FolderBrowserDialog does not expose any Events.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
Yeah, but that goes against how the standard dialog works from the users perspective and isn't intuitive. Clicking OK to Cancel? I don't think so.
I was referring to someone clicking something like a SaveAs menu item only to realize they clicked on the wrong item. The dialog is being shown now, but how does the user get back intuitively with a Cancel button? I know, the little X in the top right corner or double-clicking the top left corner or hitting Alt-F4 to close the dialog works to do this also but too many users don't know about them.
|
|
|
|
|
More to the point, you can even have a default value that the user can use as the "file name" (probably somehow related to current day/time), so that the user can/will probably just click OK to save it.
And trust me, it's very likely the user will choose that default 95% of the time
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
Write your own dialog.
If it's not broken, fix it until it is
|
|
|
|
|
how are you all.
i am new to asp.net and c#. i need help.
well my question is, i have a textbox in which a user have to enter a float value in the webform.
and i want to manipulate that value in a calculation.
so have created a class for the calculation which is Sales class. in that class i have declared Price as a float value,the value which should be obtained from the textbox.ie public float Price {get;set;}
Now my problem is with binding/linking the Price variable with the textbox in the button_click method.
initially i had done it this way:
in my .aspx.cs file i have created an object of the class in this case :
Sales s = new Sales ();
protected void button_Click (object sender EventArgs e)
{
s.Price =Convert.ToInt32(Textbox1.Text);
s.Save();
}
i want the Price value to be saved in my database after a user clicks the SAVE button from the webform.
Now the problem is when i run the application there is an error (
Hide Copy Code
An exception of type 'System.FormatException occur but was not handred in the mscorlib.dll but was not handled in the user code
)
on the line :
s.Price = Convert.ToInt32(Textbox1.Text);
could i have done something wrong in the code?
modified 2-Feb-16 2:33am.
|
|
|
|
|
You say you want the user to enter a 'float, but your code shows you try to convert what's in the TextBox to an integer.
You should be using float.TryParse to get/validate the user's input; example:
float result;
if (float.TryParse(tbUserName.Text, NumberStyles.Number, System.Globalization.NumberFormatInfo.InvariantInfo, out result))
{
}
else
{
} But, if you do use 'float, don't be surprised if when the user enters "0.123456789" in the TextBox that 'tryParse will return that as: 0.123456791.
'float is low precision.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
modified 2-Feb-16 3:04am.
|
|
|
|
|
|
Yes - you have assumed that the user can type, and won't make any mistakes!
If the user types "Hello" or "1.1", then the Convert will fail and throw an exception.
Instead, use TryParse:
int price;
if (!int.TryParse(Texbox1.Text, out price))
{
... Report problem to user and ask him to re-enter
return;
}
s.Price = price;
s.Save();
BTW: Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "Textbox1" is the price today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbPrice" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbPRice" in three keystrokes, where "Textbox1" takes thinking about and 8 keystrokes...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
note the OP talks about using a 'float, but the code used 'int
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
I see you fixed your code to reflect that - good idea!
A float is probably what he wanted - or better is probably Decimal given that it's a Price.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: I see you fixed your code to reflect that Nope, I wrote code using 'float from the git-go ... in a temporary loss of sanity where I assumed the OP meant what he wrote, rather than what he coded
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
hi thank you it worked. for Textbox name i had t name it that way for my question to be understood but its named something else in my code.thanx .
|
|
|
|
|
how are you all.
i am new to asp.net and c#. i need help.
well my question is, i have a textbox in which a user have to enter a float value in the webform.
and i want to manipulate that value in a calculation.
so have created a class for the calculation which is Sales class. in that class i have declared Price as a float value,the value which should be obtained from the textbox.ie public float Price {get;set;}
Now my problem is with binding/linking the Price variable with the textbox in the button_click method.
initially i had done it this way:
in my .aspx.cs file i have created an object of the class in this case :
Sales s = new Sales ();
protected void button_Click (object sender EventArgs e)
{
s.Price =Convert.ToInt32(Textbox1.Text);
s.Save();
}
i want the Price value to be saved in my database after a user clicks the SAVE button from the webform.
Now the problem is when i run the application there is an error (
Hide Copy Code
An exception of type 'System.NullReferenceException' occurred in Version1.dll but was not handled in user code
)
on the line :
s.Price = Convert.ToInt32(Textbox1.Text);
could i have done something wrong in the code?
|
|
|
|
|
how are you all.
i am new to asp.net and c#. i need help.
well my question is, i have a textbox in which a user have to enter a float value in the webform.
and i want to manipulate that value in a calculation.
so have created a class for the calculation which is Sales class. in that class i have declared Price as a float value,the value which should be obtained from the textbox.ie public float Price {get;set;}
Now my problem is with binding/linking the Price variable with the textbox in the button_click method.
initially i had done it this way:
in my .aspx.cs file i have created an object of the class in this case :
Sales s = new Sales ();
protected void button_Click (object sender EventArgs e)
{
s.Price =Convert.ToInt32(Textbox1.Text);
s.Save();
}
i want the Price value to be saved in my database after a user clicks the SAVE button from the webform.
Now the problem is when i run the application there is an error (
Hide Copy Code
An exception of type 'System.NullReferenceException' occurred in Version1.dll but was not handled in user code
)
on the line :
s.Price = Convert.ToInt32(Textbox1.Text);
could i have done something wrong in the code?
|
|
|
|
|
I have a method something like this.
private void PrintSomething()
{
}
then calling this method like this
MethodInvoker mi = new MethodInvoker(PrintSomething);
mi.BeginInvoke(null, null);
This will work pretty well on win7 and up, but if running it on Win XP will cause a very high cpu usage and will it eat up the memory then the desktop will freeze.
but just calling the method synchronously everything is fine under win XP.
private void btn_click(object sender, EventArgs e)
{
PrintSomething();
}
Any thought about this?
I will appreciate for any advice will.
Thanks.
modified 2-Feb-16 1:03am.
|
|
|
|
|
Suggestions:
1. Try debugging it. Or it's not possible?
2. If not debugging, do some logging within the PrintSomething method. By what you're saying, it looks like you might end up calling PrintSomething method too many times
3. You can also ask if IsInvokeRequired first.
4. A profiler? (dotTrace comes to mind)
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
Thanks for the advice, but I was end up not using asynchronous method execution if the OS is windows XP, it is hard to deal with some user that cant get over to their OS's and hardware.
|
|
|
|
|
mi.BeginInvoke(null, null) executes your PrintSomething() method asynchronously on a threadpool thread. Is that what you intended or did you mean to use Control.BeginInvoke(mi) to execute PrintSomething on the UI thread?
|
|
|
|
|
Yeah i just want to execute it asynchronously, but i was end up using synchronous if it detects that the OS is XP.
BTW Thanks
|
|
|
|
|
hello,
I want to retrieve a date from the result of a query in a variable:
using (OdbcConnection connexion_source = new OdbcConnection(con_source))
using (OdbcCommand command_source = connexion_source.CreateCommand())
{
command_source.CommandText = "select max(date) from thisdet;";
OdbcDataAdapter MyAdapter = new OdbcDataAdapter(command_source);
MyAdapter.Fill(dt_source);
}
i want to retrieve the date in a variable.
you have idea ?
thank you
|
|
|
|
|
Whenever you want to retrieve just a single value from a database you should use ExecuteScalar[^] :
using (OdbcConnection connexion = new OdbcConnection(con_source))
using (OdbcCommand command = connexion.CreateCommand())
{
command.CommandText = "select max(date) from thisdet;";
object result = command.ExecuteScalar();
if(result != null)
{
DateTime resultDate = (DateTime)result;
}
else
{
}
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
thank's
|
|
|
|