Link to home
Start Free TrialLog in
Avatar of Stacie
StacieFlag for United States of America

asked on

How to read file from a folder?

I have the following code and I'm trying to read all my image file from my upload folder. But I'm not sure what I did wrong with this code bellow.
I don't believe the path = Path.Combine logic is correct....

    var folderName = "";
    var path = "";
    var files = new List<string>();
        folderName = Server.MapPath("/Uploads/").ToString();
        path = Path.Combine(Server.MapPath("/"), folderName);
        foreach(var file in Directory.GetFiles(path)){

<!DOCTYPE html>

<html lang="en">
        <meta charset="utf-8" />
        <link rel="stylesheet" href="@Href("~/Content/tinycarousel.css")" type="text/css" />
        <link rel="stylesheet" href="@Href("~/Content/jquery.fancybox-1.3.4.css")" type="text/css" />
        <script type="text/javascript" src="@Href("~/Scripts/jquery-1.6.2.min.js")"></script>
        <script type="text/javascript" src="@Href("~/Scripts/jquery.tinycarousel.min.js")"></script>
        <script type="text/javascript" src="@Href("~/Scripts/jquery.fancybox-1.3.4.pack.js")"></script>
        <script type="text/javascript">
        <div id="slider-code">
            <a class="buttons prev" href="#">left</a>
            <div class="viewport">
                <ul class="overview">
                    @foreach(var file in files){
                            <a class="thumb" href="Uploads/@folderName/@file.Replace("_thumb", "")">
                                <img src="Uploads/@folderName/@file" alt=""/>
            <a class="buttons next" href="#">right</a>

Open in new window

Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial