Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am facing an issue in mvc 4 web api .
I want to sent comma seprated image id like 1,2,3 and want to get all 3 images using mvc 4 web api.

i am using that code now

public class ImageServiceController : ApiController
        public HttpResponseMessage Get(string id)
                var result = new HttpResponseMessage(HttpStatusCode.OK);
                String[] strArray = id.Split(',');
                int[] intArray = new int[strArray.Length];
                for (int i = 0; i < strArray.Length; i++)
                    intArray[i] = int.Parse(strArray[i]);
                    String filePath = HostingEnvironment.MapPath("~/Images/" + intArray[i] + ".png");
                    FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate);
                    Image image = Image.FromStream(fileStream);
                    MemoryStream memoryStream = new MemoryStream();
                    image.Save(memoryStream, ImageFormat.Png);
                    result.Content = new ByteArrayContent(memoryStream.ToArray());
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                return result;
            catch (Exception ex)
                return new HttpResponseMessage(HttpStatusCode.NotFound);

Thanks in advance
Updated 1-Jun-14 23:21pm
norbitrial 2-Jun-14 6:31am    
What is the problem with the code? Can you please provide us more information?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900