Copied to clipboard

Flag this post as spam?

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


  • ChristophC 17 posts 54 karma points
    Oct 08, 2015 @ 07:57
    ChristophC
    0

    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 1439 posts 6318 karma points MVP 4x c-trib
    Oct 08, 2015 @ 08:12
    Nik
    0

    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 260 posts 515 karma points
    Oct 08, 2015 @ 08:58
    Ben McKean
    0

    Not really Umbraco specific one but you'll be able to do this using Directory.GetFiles (https://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx)

    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 17 posts 54 karma points
    Oct 08, 2015 @ 10:10
    ChristophC
    1

    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 260 posts 515 karma points
    Oct 08, 2015 @ 10:22
    Ben McKean
    0

    You could also use the cropping functionality in http://imageprocessor.org/ 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:

Draft