locked
how to display the list images from the server folder in web api in asp.net with C# RRS feed

  • Question

  • User-1722422105 posted

    Hi All

    i am creatng the Web api for display for list of images 

    please  help on this issue how i retrive the images?

    Thanks and regards

    siddu

    Friday, June 1, 2018 10:16 AM

All replies

  • User632428103 posted

    Hello, 

    in your api controller add a get method who retrieve the files from the server as this => it's a sample

    public IEnumerable<string> Get()
            {
                string dirPath = Path.Combine(ConfigurationManager.AppSettings["SERVER FILE PATH "].ToString());
                List<string> files = new List<string>();
                DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
                foreach (FileInfo fInfo in dirInfo.GetFiles())
                {
                    files.Add(fInfo.Name);
                }
                return files.ToArray();
            }

    add on the view , add a call jquery for example and display them 

    <script type="text/javascript">
        $.getJSON('api/apiName', function (data) 
    {
            var fileList = $("#files");
    
            // browse over file
            $.each(data, function (key, val) {
                var row = ('<li>' + val +'</li>');
                $("#files").append(row);
            });
        });
    </script>
    <ul id="files">
    </ul>

    don't forget to add the jquery library

    Friday, June 1, 2018 11:38 AM
  • User475983607 posted

    Hi All

    i am creatng the Web api for display for list of images 

    please  help on this issue how i retrive the images?

    Thanks and regards

    siddu

    There is no user interface in Web API.  Can you clarify the problem you are trying to solve? 

    Friday, June 1, 2018 12:11 PM
  • User-2082498127 posted

    Tks. I need your help

    Tuesday, June 5, 2018 4:37 AM