|
<blockquote class="FQ"><div class="FQA">ParimalaRadjaram wrote:</div>For example, if a text file is opened by name "abc.txt". When I'm closing this file, a message must be prompted that "File abc.txt is closed". I need to do this in C#.</blockquote>
I have written a console application for you:
<code>
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace OnCloseEventExample
{
class SpecFileStream : System.IO.FileStream
{
private string _fileName;
public string FileName
{
get { return _fileName; }
set { _fileName = value; }
}
//lazy to create a new delegate. We are using System.EventHandler
public event EventHandler FileClose;
public SpecFileStream(string filePath, FileMode mode)
: base(filePath, mode)
{
_fileName = Path.GetFileName(filePath);
}
public override void Close()
{
FileClose(this, new EventArgs());
base.Close();
}
}
class Program
{
static void Main(string[] args)
{
string filePath = "";
if(args.Length < 1)
{
filePath = @"C:\test.txt";
}
else
{
filePath = args[0];
}
SpecFileStream sfs = new SpecFileStream(
filePath,
System.IO.FileMode.Create
);
sfs.FileClose += new EventHandler(sfs_FileClose);
byte[] data = Encoding.ASCII.GetBytes("writes to file this");
sfs.Write(data, 0, data.Length);
sfs.Close();
}
static void sfs_FileClose(object sender, EventArgs e)
{
SpecFileStream sfs = sender as SpecFileStream;
if (sfs != null)
{
Console.WriteLine("File " + sfs.FileName + " is being closed!");
}
else
{
throw new Exception("Invalid sender object class!");
}
}
}
}
</code>
If any comments are needed, feel free to ask.
|
|
|
|
|
I'll try this and let u know. Thanks a lot.
Parimala
|
|
|
|
|
When i'm compiling the code, i'm getting the following error. Could just tell me why this happens?
'System.IO.FileStream.FileStream()' is inaccessible due to its protection level
Parimala
|
|
|
|
|
yes...!
it is posible but you have to get location where is your file is located. then using FSO object then you can get all files name of the directory.
cheer
Pavan Pareta
|
|
|
|
|
Pavan_pareta wrote: it is posible but you have to get location where is your file is located. then using FSO object then you can get all files name of the directory
Why the FileSystemObject? There are better .NET ways of doing this.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi all,
I need to create a custom control DataGrid that should contain ListBox
control as one of the column that allow to select a value from multiple values.
This is possible in DataGridView.
But is it possible in DataGrid ?
Thanks in Advance
Karthik M
|
|
|
|
|
YES IT IS POSSIBLE...
I HAVE DONE IN PAST... I DONT HAVE THE CODE FOR THAT RIGHT NOW.. BU TU CAN GO CHECK OUT IN CsharpCORNER.COM.
basically the idea is... fill ur datagrid... then add new column to it, and then add a combo to it.. finally fill ur combos according to the condition..... it is simple but lengthy task...
hpoe u can find ur way.....
|
|
|
|
|
Thanks for your reply.
But i need to add multiselect listbox in the datagrid.
Is there any way to do this ?
Karthik M
|
|
|
|
|
You can, normally, create column types with cells that host controls of your choosing, whatever they might be. You have to define classes that derive from DataGridViewColumn and DataGridViewCell . Here[^] is shown an example for the case of a DateTimePicker control. Adapt the code to a ListBox.
Oh, yes there is some work to do for it, but I guess you enjoy it!
SkyWalker
|
|
|
|
|
Thanks Mircea,
I guess i have clearly mentioned in my query that i can include the ListBox
in DataGridView.
But i cant include the ListBox in DataGrid.
Is it possible ?
-- modified at 23:29 Tuesday 30th January, 2007
Karthik M
|
|
|
|
|
Hey Karthik
the way i told u u can implement it,
ok let me remind me my self ur question...
u want add multiselect listbox... in datagrid...
yes it is possible. and in the same fashion i told u in my previous post....
dont mid let me ask u a question.... do know the diff.. between Combobox and list box, in terms of web... and windows....
but what u want to achive with that... i think u r trying to do something very complicated in ur page.....
|
|
|
|
|
I´m trying to read a xml file into typed dataset, but I really can´t get it done. Here´s a simple code of what I´m trying to do:
typedDS.ReadXml("d:\\Test.xml");
I don´t get any exception, but there are no records in the dataset. Can anyone help me with this?
cellardoor
|
|
|
|
|
does D:\Test.xml match the schema of the typed dataset?... If it doesn't, you may not have any data in your typed tables, but it may have created a new table from the xml data.
Try iterating through your typedDS.Tables to check this out.
Fan of Donny Darko?
|
|
|
|
|
yes the xml file D:\Test.xml does match the schema of the typed datased. I tryied to validate it first and the validation was successful... I also itarated through the dataset tables and there aren´t any other tables.
cellardoor
|
|
|
|
|
hmmm.... perhaps try:
typedDS.ReadXml("d:\\Test.xml",XmlReadMode.InferTypedSchema);
or XmlReadMode.InferSchema
|
|
|
|
|
thanks now it´s working...
cellardoor
|
|
|
|
|
i don't suppouse d:\Test.xml is an empty file
well, i've been using this method for some time and it works fine for me.
maybe you should try adding some data to the tables in the dataset then ds.WriteXml(file) and then try newDs.ReadXml(file)..
if this will work i'd mean your file is somehow bad, and if not then hmm..
you could also try putting the typedDS.ReadXml("d:\\Test.xml"); in try-carch block.. i had some situations when no error occured and after surrounding code with try-catch exception was handled..
life is study!!!
|
|
|
|
|
comboBoxWorkers.DataSource = PersonsBindingSource;
comboBoxWorkers.DisplayMember = "Name";
comboBoxWorkers.ValueMember = "PersonID";
In the SelectedIndexChanged event query the SelectedValue but it doesn't return the right value.
How can i get the SelectedValue when the user selects a name from the combobox?
|
|
|
|
|
Works for me. What value it is returning? another member?
|
|
|
|
|
It returns the ID but not the ID that match to the selected name.
|
|
|
|
|
That's simply impossible - is the selected text correct?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Better u can try in combobox_selected value event
int i;
i=combobox.selectedValue
Hope this works!
Parimala
|
|
|
|
|
Well, I'm not sure what you're suggesting. The event works, whenever I've used it ( or anyone else )
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Probably, as in the case of selectedIndex changed, i think we cannot get the selected value.
As of my code, i use the selected value property in the selectedvalue changed event.
Parimala
|
|
|
|
|
The SelectedText is "" but the text is correct
|
|
|
|