Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all articles
Browse latest Browse all 956

how to retrive the all the image from the folder in C#

$
0
0

Hi 

 i am creating web api for displaying the all images from the folder haveing images

 below is my code, but it displaying the last image from the folder.


HttpResponseMessage Response = new HttpResponseMessage(HttpStatusCode.OK);

string[] filesindirectory = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/images"));
List<String> images = new List<string>(filesindirectory.Count());

foreach (string item in filesindirectory)
{

images.Add(String.Format("~/images", System.IO.Path.GetFileName(item)));
byte[] fileData = File.ReadAllBytes(item);
Response.Content = new ByteArrayContent(fileData);

}

Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return Response;


Viewing all articles
Browse latest Browse all 956

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>