This documentation is archived and is not being maintained.

DiscoveryDocument::Write Method (Stream)

Writes this DiscoveryDocument into the passed Stream.

Namespace:  System.Web.Services.Discovery
Assembly:  System.Web.Services (in System.Web.Services.dll)

public:
void Write(
	Stream^ stream
)

Parameters

stream
Type: System.IO::Stream

The Stream into which this DiscoveryDocument is written.

The following code example writes a discovery document out to a file named log.txt using the Write method.

// Create an object of the 'DiscoveryDocument'.
DiscoveryDocument^ myDiscoveryDocument = gcnew DiscoveryDocument;

// Create an XmlTextReader with the sample file.
XmlTextReader^ myXmlTextReader = gcnew XmlTextReader(
   "http://localhost/example_Write1_cs.disco" );

// Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument::Read( myXmlTextReader );

// Write the DiscoveryDocument into the stream.
FileStream^ myFileStream = gcnew FileStream(
   "log.txt",FileMode::OpenOrCreate,FileAccess::Write );
myDiscoveryDocument->Write( myFileStream );

myFileStream->Flush();
myFileStream->Close();

// Display the contents of the DiscoveryDocument onto the console.
FileStream^ myFileStream1 = gcnew FileStream(
   "log.txt",FileMode::OpenOrCreate,FileAccess::Read );
StreamReader^ myStreamReader = gcnew StreamReader( myFileStream1 );

// Set the file pointer to the begin.
myStreamReader->BaseStream->Seek( 0, SeekOrigin::Begin );
Console::WriteLine( "The contents of the DiscoveryDocument are-" );
while ( myStreamReader->Peek() > -1 )
{
   Console::WriteLine( myStreamReader->ReadLine() );
}
myStreamReader->Close();
// Create an object of the 'DiscoveryDocument'.
DiscoveryDocument* myDiscoveryDocument = new DiscoveryDocument();

// Create an XmlTextReader with the sample file.
XmlTextReader* myXmlTextReader = new XmlTextReader(S"http://localhost/example_Write1_cs.disco");

// Read the given XmlTextReader.
myDiscoveryDocument = DiscoveryDocument::Read(myXmlTextReader);

// Write the DiscoveryDocument into the stream.
FileStream* myFileStream = new FileStream(S"log.txt", FileMode::OpenOrCreate, FileAccess::Write);
myDiscoveryDocument->Write(myFileStream);

myFileStream->Flush();
myFileStream->Close();

// Display the contents of the DiscoveryDocument onto the console.
FileStream* myFileStream1 = new FileStream(S"log.txt", FileMode::OpenOrCreate, FileAccess::Read);
StreamReader* myStreamReader = new StreamReader(myFileStream1);

// Set the file pointer to the begin.
myStreamReader -> BaseStream -> Seek(0, SeekOrigin::Begin);
Console::WriteLine(S"The contents of the DiscoveryDocument are-");
while (myStreamReader->Peek() > -1)
   Console::WriteLine(myStreamReader->ReadLine());
myStreamReader->Close();

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: