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

FileWebRequest.GetRequestStream Method

Returns a Stream object for writing data to the file system resource.

Namespace:  System.Net
Assembly:  System (in System.dll)
public override function GetRequestStream() : Stream

Return Value

Type: System.IO.Stream
A Stream for writing data to the file system resource.
ExceptionCondition
WebException

The request times out.

The GetRequestStream method provides synchronous access to the Stream. For asynchronous access, use the BeginGetRequestStream and EndGetRequestStream methods.

The following code example uses the GetRequestStream method to obtain a stream instance used to write to the file. Refer to the complete example in the FileWebRequest class.

No code example is currently available or this language may not be supported.
			// Enter the string to write into the file.
			Console::WriteLine(S"Enter the string you want to write:");
			String* userInput = Console::ReadLine();
			// Convert the string to Byte array.
			ASCIIEncoding* encoder = new ASCIIEncoding();
			Byte byteArray[] = encoder->GetBytes(userInput);
			// Set the ContentLength property.
			myFileWebRequest->ContentLength=byteArray->Length;
			String* contentLength = myFileWebRequest->ContentLength.ToString();
			Console::WriteLine(S"\nThe content length is {0}.", contentLength);
			// Get the file stream handler to write into the file.
			Stream* readStream=myFileWebRequest->GetRequestStream();

			// Write to the file stream.
			// Note. In order for this to work the file must be accessible
			// on the network. This can be accomplished by setting the property
			// sharing of the folder containg the file. The permissions
			// can be set so everyone can modify the file.
			// FileWebRequest::Credentials property cannot be used for this purpose.
			readStream->Write(byteArray, 0, userInput->Length);

			Console::WriteLine(S"\nThe String you entered was successfully written into the file.");

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.