Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • ChristophC 21 posts 60 karma points
    Oct 08, 2015 @ 07:57

    Get Files from Directory

    Hello Everybody!

    Is there a possibility to list files from a directory on the webserver? It is not a media folder or an umbraco folder, just a folder on the same server as the umbraco - Installation which I have created via FTP with Webcam-Pictures in it.

    I want to list the files from the folder via c# in a partial view!

    Thanks, Christoph

  • Nik 1527 posts 6760 karma points MVP 5x c-trib
    Oct 08, 2015 @ 08:12

    It should be possible, there are several options available to you. Saying that you just need to consider permissions. If the account that the website is running as, doesn't have access then you wouldn't be able to do it directly I don't think.

  • Ben McKean 270 posts 546 karma points
    Oct 08, 2015 @ 08:58
    Ben McKean

    Not really Umbraco specific one but you'll be able to do this using Directory.GetFiles (

    This returns a string array for each of the files found and then you can do whatever you need to with. You can also pass in a wildcard if you'd like to only get certain files.

    As Nik said, important to get permissions right

  • ChristophC 21 posts 60 karma points
    Oct 08, 2015 @ 10:10

    Perfect! Thank you!

    I have solved it that way in a Partial View:

    string folderPath = Server.MapPath("~/img/webcam");
    string[] files = Directory.GetFiles(folderPath);    
        @foreach (string item in files){
            <img class="img-responsive" src="/img/webcam/@Path.GetFileName(item)?width=250px"/>
  • Ben McKean 270 posts 546 karma points
    Oct 08, 2015 @ 10:22
    Ben McKean

    You could also use the cropping functionality in for your images thats built into Umbraco.

    Not 100% sure if it works with images outside of the Umbraco media library but think it does....?

Please Sign in or register to post replies

Write your reply to: