Which code segment should you use?

You are implementing a method named ProcessFile that retrieves data files from web servers and FTP servers.
The ProcessFile () method has the following method signature:
Public void ProcessFile(Guid dataFileld, string dataFileUri)
Each time the ProcessFile() method is called, it must retrieve a unique data file and then save the data file to
disk.
You need to complete the implementation of the ProcessFile() method. Which code segment should you use?

You are implementing a method named ProcessFile that retrieves data files from web servers and FTP servers.
The ProcessFile () method has the following method signature:
Public void ProcessFile(Guid dataFileld, string dataFileUri)
Each time the ProcessFile() method is called, it must retrieve a unique data file and then save the data file to
disk.
You need to complete the implementation of the ProcessFile() method. Which code segment should you use?

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
* WebRequest.Create Method (Uri)
Initializes a new WebRequest instance for the specified URI scheme.* Example:
1. To request data from a host server
Create a WebRequest instance by calling Create with the URI of the resource.
C#
WebRequest request = WebRequest.Create(“http://www.contoso.com/”);
2. Set any property values that you need in the WebRequest. For example, to enable authentication, set the
Credentials property to an instance of the NetworkCredential class.
C#
request.Credentials = CredentialCache.DefaultCredentials;
3. To send the request to the server, call GetResponse . The actual type of the returned WebResponse object
is determined by the scheme of the requested URI.
C#
WebResponse response = request.GetResponse();
4. To get the stream containing response data sent by the server, use the GetResponseStream method of the
WebResponse.
C#
Stream dataStream = response.GetResponseStream ();



Leave a Reply 2

Your email address will not be published. Required fields are marked *


tom

tom

Option B will throw an exception on execution, as FileWebRequest.Create() returns a HttpWebRequest, and cannot be casted to FileWebRequest. So request will be null.

Option C uses the wrong signature of StreamWriter. When passed in constructor, the stream needs to be writable, as it assumes you are passing the target.

That is why D is correct, as it uses to correct syntax

tom

tom

Also Option A is totally wrong, just by looking at it.