Click here to Skip to main content
15,922,145 members
Home / Discussions / C#
   

C#

 
AnswerRe: Get File Name Pin
Pete O'Hanlon29-Jan-07 23:33
mvePete O'Hanlon29-Jan-07 23:33 
GeneralRe: Get File Name Pin
ParimalaRadjaram29-Jan-07 23:35
ParimalaRadjaram29-Jan-07 23:35 
GeneralRe: Get File Name Pin
bobsugar22229-Jan-07 23:39
bobsugar22229-Jan-07 23:39 
GeneralRe: Get File Name Pin
ParimalaRadjaram29-Jan-07 23:41
ParimalaRadjaram29-Jan-07 23:41 
GeneralRe: Get File Name Pin
bobsugar22229-Jan-07 23:59
bobsugar22229-Jan-07 23:59 
AnswerRe: Get File Name Pin
engsrini30-Jan-07 0:47
engsrini30-Jan-07 0:47 
GeneralRe: Get File Name Pin
ParimalaRadjaram30-Jan-07 2:51
ParimalaRadjaram30-Jan-07 2:51 
AnswerRe: Get File Name Pin
greenpci30-Jan-07 1:54
greenpci30-Jan-07 1:54 
<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.
GeneralRe: Get File Name Pin
ParimalaRadjaram30-Jan-07 2:55
ParimalaRadjaram30-Jan-07 2:55 
GeneralRe: Get File Name Pin
ParimalaRadjaram30-Jan-07 17:48
ParimalaRadjaram30-Jan-07 17:48 
AnswerRe: Get File Name Pin
PavanPareta30-Jan-07 2:58
PavanPareta30-Jan-07 2:58 
GeneralRe: Get File Name Pin
Pete O'Hanlon30-Jan-07 3:52
mvePete O'Hanlon30-Jan-07 3:52 
QuestionListBox as a DataGrid Cell Pin
karthik Tamizhmathi29-Jan-07 22:57
karthik Tamizhmathi29-Jan-07 22:57 
AnswerRe: ListBox as a DataGrid Cell Pin
blue_arc30-Jan-07 1:26
blue_arc30-Jan-07 1:26 
GeneralRe: ListBox as a DataGrid Cell Pin
karthik Tamizhmathi30-Jan-07 1:42
karthik Tamizhmathi30-Jan-07 1:42 
AnswerRe: ListBox as a DataGrid Cell Pin
Mircea Puiu30-Jan-07 4:15
Mircea Puiu30-Jan-07 4:15 
GeneralRe: ListBox as a DataGrid Cell [modified] Pin
karthik Tamizhmathi30-Jan-07 17:24
karthik Tamizhmathi30-Jan-07 17:24 
GeneralRe: ListBox as a DataGrid Cell Pin
blue_arc30-Jan-07 21:19
blue_arc30-Jan-07 21:19 
Questionread xml file into typed dataset Pin
cellardoor071629-Jan-07 22:36
cellardoor071629-Jan-07 22:36 
AnswerRe: read xml file into typed dataset Pin
bobsugar22229-Jan-07 22:50
bobsugar22229-Jan-07 22:50 
GeneralRe: read xml file into typed dataset Pin
cellardoor071629-Jan-07 22:58
cellardoor071629-Jan-07 22:58 
GeneralRe: read xml file into typed dataset Pin
bobsugar22229-Jan-07 23:05
bobsugar22229-Jan-07 23:05 
GeneralRe: read xml file into typed dataset Pin
cellardoor071629-Jan-07 23:13
cellardoor071629-Jan-07 23:13 
AnswerRe: read xml file into typed dataset Pin
Seishin#30-Jan-07 4:25
Seishin#30-Jan-07 4:25 
QuestionCombobox SelectedValue problem Pin
zt.Prog29-Jan-07 22:30
zt.Prog29-Jan-07 22:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.