FileWebRequest.GetRequestStream メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > FileWebRequest.GetRequestStream メソッドの意味・解説 

FileWebRequest.GetRequestStream メソッド

ファイル システム リソースデータ書き込む Stream オブジェクト返します

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Overrides Function
 GetRequestStream As Stream
Dim instance As FileWebRequest
Dim returnValue As Stream

returnValue = instance.GetRequestStream
public override Stream GetRequestStream ()
public:
virtual Stream^ GetRequestStream () override
public Stream GetRequestStream ()

戻り値
ファイル システム リソースデータ書き込む Stream

例外例外
解説解説

GetRequestStream メソッドは、Stream への同期アクセス提供します非同期アクセスでは、BeginGetRequestStream メソッドと EndGetRequestStream メソッド使用します

使用例使用例

GetRequestStream メソッド使用してファイル書き込むために使用するストリーム インスタンス取得するコード例次に示します詳細については、FileWebRequest クラストピック参照してください

' Enter the string to write to the file.
Console.WriteLine("Enter the string you want to write:")
Dim userInput As String
 = Console.ReadLine()

' Convert the string to a byte array.
Dim encoder As New ASCIIEncoding
Dim byteArray As Byte()
 = encoder.GetBytes(userInput)

' Set the ContentLength property.
myFileWebRequest.ContentLength = byteArray.Length

Dim contentLength As String
 = myFileWebRequest.ContentLength.ToString()

Console.WriteLine(ControlChars.Lf + "The content length is {0}.",
 contentLength)


' Get the file stream handler to write to the file.
Dim readStream As Stream = myFileWebRequest.GetRequestStream()

' Write to the stream. 
' Note. 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.  
' FileWebRequest.Credentials property cannot be used for this purpose.
readStream.Write(byteArray, 0, userInput.Length)


Console.WriteLine(ControlChars.Lf + "The String you entered was
 successfully written to the file.")

// Enter the string to write to the file.
Console.WriteLine ("Enter the string you want to write:");

string userInput = Console.ReadLine ();

// Convert the string to a 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 ("\nThe content length is {0}.", contentLength);

// Get the file stream handler to write to the file.
Stream readStream = myFileWebRequest.GetRequestStream ();

// Write to the file stream. 
// Note.  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. 
// FileWebRequest.Credentials property cannot be used for this purpose.
readStream.Write (byteArray, 0, userInput.Length);
Console.WriteLine ("\nThe String you entered was successfully written to the
 file.");

// Enter the string to write into the file.
Console::WriteLine( "Enter the string you want to write:"
 );
String^ userInput = Console::ReadLine();

// Convert the string to Byte array.
ASCIIEncoding^ encoder = gcnew ASCIIEncoding;
array<Byte>^byteArray = encoder->GetBytes( userInput );

// Set the ContentLength property.
myFileWebRequest->ContentLength = byteArray->Length;
String^ contentLength = myFileWebRequest->ContentLength.ToString();
Console::WriteLine( "\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( "\nThe String you entered was successfully written into
 the file." );

// Enter the string to write to the file.
Console.WriteLine("Enter the string you want to write:");
String userInput = Console.ReadLine();

// Convert the string to a byte array.
ASCIIEncoding encoder = new ASCIIEncoding();
ubyte byteArray[] = encoder.GetBytes(userInput);

// Set the ContentLength property.
myFileWebRequest.set_ContentLength(byteArray.length);
String contentLength = 
    (new Long(myFileWebRequest.get_ContentLength())).ToString();
Console.WriteLine("\nThe content length is {0}.", contentLength);

// Get the file stream handler to write to the file.
Stream readStream = myFileWebRequest.GetRequestStream();

// Write to the file stream. 
// Note.  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. 
// FileWebRequest.Credentials property cannot be used for 
// this purpose.
readStream.Write(byteArray, 0, userInput.get_Length());
Console.WriteLine("\nThe String you entered was successfully " 
    + "written to the file.");
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FileWebRequest クラス
FileWebRequest メンバ
System.Net 名前空間
BeginGetRequestStream


このページでは「.NET Framework クラス ライブラリ リファレンス」からFileWebRequest.GetRequestStream メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からFileWebRequest.GetRequestStream メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からFileWebRequest.GetRequestStream メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

FileWebRequest.GetRequestStream メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FileWebRequest.GetRequestStream メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS