Home > Articles > Programming > C#

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Final Implementation

We implement the ImageListtoFiles method by combining motif 5', motif 6, motif 1', and motif 7. These motifs are highlighted in red, green, blue, and aqua, respectively (see Listing 68).

Listing 68—ImageListtoFiles Completed Method: Combining Motifs 1', 5', 6', and 7

public void ImageListtoFiles(ArrayList file_list)
{
int i;
string filename;
FileStream fs;

WebRequest req;
WebResponse res;
Stream   str;

int ch;

for (i=0; i < file_list.Count; i++) {
 filename=Convert.ToString(file_list[i]);
 filename=filename.Replace("/", "_");
 filename= folder+"/"+filename;
 fs=new FileStream(filename, FileMode.Create);

 req = WebRequest.Create(base_url+file_list[i]);
 res = req.GetResponse();
 str = res.GetResponseStream();

 while ((ch=str.ReadByte())!=-1)
  fs.WriteByte(Convert.ToByte(ch));

 str.Close();
 res.Close();
 fs.Close();
}

}

Don't forget to close the web Stream (str), WebResponse (res), and FileStream (fs) objects.

  • + Share This
  • 🔖 Save To Your Account