locked
Good codeing? Is there a better way to do this? RRS feed

  • Question

  • Hi,

    I am new to programing. I have used PHP before and been playing with VS2008 for a few weeks. I am trying to make web page that will display my file from different folders on the computer and make them downloadable . this is just using a test folder at the moment.

    To do this i had to make a virtual directory that is called "c" and is mapped to the "c:\" drive.
    I cant help but think there would be a better way to do this? Any info would be great.

    Deafault.aspx.cs
    1 using System;  
    2 using System.Collections.Generic;  
    3 using System.Web;  
    4 using System.Web.UI;  
    5 using System.Web.UI.WebControls;  
    6 using System.IO;  
    7  
    8 namespace Server_Machine  
    9 {  
    10     public partial class _Default : System.Web.UI.Page  
    11     {  
    12         protected void Page_Load(object sender, EventArgs e)  
    13         {  
    14               
    15             DirectoryInfo dir = new DirectoryInfo(@"c:\files");  
    16  
    17             FileInfo[] file = dir.GetFiles();  
    18             Response.Write("<ul>");  
    19  
    20             foreach (FileInfo fi in file)  
    21             {  
    22  
    23                 string url = fi.FullName.ToString().Replace(@"\","/");  
    24                 string nav = url.Replace("c:""/c");  
    25  
    26  
    27                 Response.Write("<li><a href=\"" + nav + "\">" + fi.Name + "</a></li>");  
    28                   
    29             }  
    30             Response.Write("</ul>");  
    31               
    32               
    33               
    34  
    35         }  
    36  
    37           
    38     }  
    39 }  
    40  



    Thanks in advance
    Tyron.
    • Moved by jack 321 Monday, June 9, 2008 4:24 AM ASP.Net download question
    Thursday, June 5, 2008 7:56 AM

Answers

  • You have posted in the wrong forum.
    This is a C# forum and you have asked a ASP.NET question.
    Please post here.
    Always mark the post that helped you as "Answer". That helps future users to locate answers quickly.
    Thursday, June 5, 2008 9:16 AM

All replies

  • You have posted in the wrong forum.
    This is a C# forum and you have asked a ASP.NET question.
    Please post here.
    Always mark the post that helped you as "Answer". That helps future users to locate answers quickly.
    Thursday, June 5, 2008 9:16 AM
  • Sorry i assumed because i was using visual studio and it was c# code the would be the place to code. Thanks ill re post elswhere
    Thursday, June 5, 2008 9:58 AM