|
THANKS
i'll try it
Have Fun
Never forget it
|
|
|
|
|
I have situation in code where I have to deal with the File Creation Time.
I have used System.IO.File class to check for the existence of the File and then deleted it, then in another function created the File using FileStream Class with FileMode.Create and CreateNew Parameter.
File is delete in both cases from disk, (as it shows in the folder - with FileInfo and System.IO.File) but when the File is created again with FileMode.Create and FileMode.CreateNew, it has the older creation date i.e. the date of the deleted file.
Can anyone help on this with a thorough and solid answer?
Muhammad Talha
|
|
|
|
|
Well, it seems strange that it would keep the old date/time but i'm sure there's a reason.
Until you find out why, you can set the creation time yourself. Sadly, i can't remember where exactly you do that, you may need to do a bit of googling.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
|
Hi all,
In my .NET 1.1 Windows application I am using the validating event to check the correct field contents of a TextBox. When the contents was wrong I used e.cancel=true; and set the Focus on the TextBox again. I am leaving the TextBox by a button click event.
I would expect that the validating event comes before a button click event occurs, but that's wrong. The button click will not be canceled.
What must be done to cancel the button click when the e.cancel event of the TextBox becomes true ?
Or can I check in my button click function if a cancel has happend anywhere ?
Thanks in advance
Frank
|
|
|
|
|
The event order is Validating, Validated and lost focus.
So before you click on the button, the text box events are fired.
You must use the validating event of the text box and use a flag on behalf of that to execute the button click.
Muhammad Talha
|
|
|
|
|
Just tried this and it works okay, add a textbox and button to a form:
<br />
private void textBox1_Validating(object sender, CancelEventArgs e)<br />
{<br />
if (string.Compare(textBox1.Text, "foo") != 0)<br />
{<br />
e.Cancel = true;<br />
}<br />
<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("bar!");<br />
}<br />
If text box hasn't got foo then there is no bar.
Doesn't matter if you tab or click away, the focus stays with the unvalidated control.
Hope this helps,
|
|
|
|
|
Thank you for your answer,
this is what I would appreciate to have.
But in my Application the MessageBox was shown !!!
This is what i don't understand.
the Button is on a Tab of the tabcontrol and the TextBox is on a panel of the same tab, don't know if this metters ?
An idea ?
Thanks
frank
|
|
|
|
|
I can only think that your event is not bound to the text control. If the validating event is cancelled then the focus will stay on the text control.
In the textbox's properties check the events and at the bottom look at Validating it should be (in the example) textBbox1_Validating
|
|
|
|
|
Hi all
In my C# class I have my simple field declared as
String MyField{
get{
return MyString;
}
}
If I use for it the delegate declared as
delegate String StringDelegate();
List< StringDelegate > a = new List< StringDelegate >(100);
List.Add( MyField );
It doesn'! work. It tells me that it cannot convert
annot convert from 'string' to 'StringDelegate'
How I can refer to my field function using delegate?
Kind Regards
ManuStone
|
|
|
|
|
Before I get to your real question, we need to make sure we are on the same page. In your code example above, MyField is a property, not a field. Below is an example of a field and a property:
private String myField = String.Empty;
public String MyProperty {
get {
return this.myField;
}
}
Now, for your question. There is no direct way to create a delegate to a property's get or set accessors. It is possible, as shown here[^], but it's somewhat of a hack. I call it a hack, because you need to pass the name of the property to get the delegate. So if you change the name of the property, then your delegate will be broken.
You may be able to use anonymous methods[^] (see Figure 10) to accomplish what you want.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
You are right! Sorry for having being not very detailed (always too hurry while work!
Many Thanks for your time and for the articles you suggested.
Manu
|
|
|
|
|
As stated in the C# Programming Guide at MSDN delegates can only be used with named or anonymous methods.
AFAIK there is no way to define a delegate for a property ("field function").
If you change your Property to something like:
String GetMyField()
{
return MyString;
}
it should work.
Cheers
Markus
|
|
|
|
|
Many Thanks. It is exactly what I did for the time being
and it is ok!(it works)
Thanks for your time!
Manu
|
|
|
|
|
Hi All,
I was just looking through MSDN and got a shock in that there is no such thing as a temporary file .. (only a memorystream)
I need someting like the C++ tmpfile() ... I need to save some to a temp file as I have a third-party plugin that can only read an XML file if I specify a filename, therefore I need a temp file on the disk ...
Is there still a way to do this ?
Thanks
kort
|
|
|
|
|
|
I find that the following code can be helpful. This class creates a temporary file that you can use, which is removed once you dispose the instantiating class.
; public class TempFile : IDisposable
{
private string _fileName;
private bool disposed = false;
public TempFile()
{
_fileName = Path.GetTempFileName();
}
public string FileName
{
get { return _fileName; }
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
}
protected void Dispose(bool dispose)
{
if (dispose && !disposed)
{
if (File.Exists(_fileName))
{
try
{
File.Delete(_fileName);
}
catch (IOException ex)
{
Trace.WriteLine(string.Format("Unable to remove temporary file because of {0}",
ex.Message));
}
}
disposed = true;
GC.SuppressFinalize(this);
}
}
#endregion
} using (TempFile tempFile = new TempFile())
{
filename = tempFile.FileName;
using (FileStream fs = new FileStream(tempFile.FileName, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine("Write to temp.");
}
fs.Close();
}
Console.WriteLine("The size of {0} is {1} bytes", tempFile.FileName,
new FileInfo(tempFile.FileName).Length);
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
To add to the 2 other answers, in .NET 2.0, there are new constructors added to System.IO.FileStream . 2 of them take a FileOption argument (can be bitwised). One of the members of this enumeration is DeleteOnClose . I leave as an excercise for you to figure out what this does
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Hi All,
Can any one help me how to implement paging with the datalist,
Backend database MySQL 5.0
Thanks for all.
chandu
chandu
chandu
|
|
|
|
|
|
I tryed impleminting but it was not much of use.
chandu
|
|
|
|
|
Sounds likely that the problem was a human interface error.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: a human interface error
PEBKAC?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
Its working fine. You must try for that.
Thanks,
Sun Rays
|
|
|
|
|
how i can make form at run time like design time .
i mean can select Object and show properties as Textbox , Labal.
123
|
|
|
|