Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

FileStream.Name Property

Gets the name of the FileStream that was passed to the constructor.

[Visual Basic]
Public ReadOnly Property Name As String
[C#]
public string Name {get;}
[C++]
public: __property String* get_Name();
[JScript]
public function get Name() : String;

Property Value

A string that is the name of the FileStream.

Remarks

The following table lists examples of other typical or related I/O tasks.

To do this... See the example in this topic...
Create a text file. Writing Text to a File
Write to a text file. Writing Text to a File
Read from a text file. Reading Text from a File
Append text to a file. Opening and Appending to a Log File

File.AppendText

FileInfo.AppendText

Retrieve a file extension. Path.GetExtension
Retrieve the fully qualified path of a file. Path.GetFullPath
Retrieve the file name and extension from a path. Path.GetFileName
Retrieve only the extension of a file. GetDirectoryName
Change the extension of a file. Path.ChangeExtension

Example

[Visual Basic, C#, C++] This code example is part of a larger example provided for System.IO.FileStream.FileStream4.

[Visual Basic] 
Private Shared Sub EndReadCallback(asyncResult As IAsyncResult)
     Dim tempState As State = _
         DirectCast(asyncResult.AsyncState, State)
     Dim readCount As Integer = _
         tempState.FStream.EndRead(asyncResult)

     Dim i As Integer = 0
     While(i < readCount)
         If(tempState.ReadArray(i) <> tempState.WriteArray(i))
             Console.WriteLine("Error writing data.")
             tempState.FStream.Close()
             Return
         End If
         i += 1
     End While

     Console.WriteLine("The data was written to {0} and " & _
         "verified.", tempState.FStream.Name)
     tempState.FStream.Close()

     ' Signal the main thread that the verification is finished.
     tempState.ManualEvent.Set()
 End Sub

[C#] 
static void EndReadCallback(IAsyncResult asyncResult)
{
    State tempState = (State)asyncResult.AsyncState;
    int readCount = tempState.FStream.EndRead(asyncResult);

    int i = 0;
    while(i < readCount)
    {
        if(tempState.ReadArray[i] != tempState.WriteArray[i++])
        {
            Console.WriteLine("Error writing data.");
            tempState.FStream.Close();
            return;
        }
    }
    Console.WriteLine("The data was written to {0} and verified.",
        tempState.FStream.Name);
    tempState.FStream.Close();

    // Signal the main thread that the verification is finished.
    tempState.ManualEvent.Set();
}

[C++] 
static void EndReadCallback(IAsyncResult* asyncResult)
{
    State* tempState = 
        dynamic_cast<State*>(asyncResult->AsyncState);
    int readCount = tempState->FStream->EndRead(asyncResult);

    int i = 0;
    while(i < readCount)
    {
        if(tempState->ReadArray[i] != tempState->WriteArray[i++])
        {
            Console::WriteLine(S"Error writing data.");
            tempState->FStream->Close();
            return;
        }
    }
    Console::WriteLine(S"The data was written to {0} "
        S"and verified.", tempState->FStream->Name);
    tempState->FStream->Close();

    // Signal the main thread that the verification is finished.
    tempState->ManualEvent->Set();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

.NET Framework Security: 

See Also

FileStream Class | FileStream Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.