1、就是列出服务器的应用程序目录列表吗?如果这样,可以:
/****************************************************************************
/ Scan the current folder, add all the child directories and files
/ For each item add the links to navigate the folder structure, the icons,
/ and other information such as the creation date, size etc.
/***************************************************************************/
private void FillFoldersAndFilesTable()
{
string location; DirectoryInfo parentDir;
DirectoryInfo[] childDirs;
FileInfo[] childFiles;
try
{
parentDir = new DirectoryInfo(Server.MapPath(folderPath));
// get all the child directories and files
childDirs = parentDir.GetDirectories();
childFiles = parentDir.GetFiles();
}
catch (Exception exc)
{
StatusMessage.Text = exc.Message;
StatusMessage.Visible = true;
return;
} TableRow rowItem;
TableCell cellItemIcon;
TableCell cellItemLink;
TableCell cellSize;
TableCell cellDownload;
TableCell cellAttributes;
TableCell cellOperations;
TableCell cellCreated;
TableCell cellLastModified;
HyperLink linkRename;
HyperLink linkItem;
HyperLink linkDownload;
CheckBox checkItem;
HyperLink linkSetAttribs;
Label labelAttributes;
System.Web.UI.WebControls.Image imgItemIcon; Style styleFolderRow = new Style();
styleFolderRow.CssClass = FolderStyle.Text;
Style styleFileRow = new Style();
styleFileRow.CssClass = FileStyle.Text;
Style styleLink = new Style();
styleLink.CssClass = "GridLink"; // if the current folder is not the site root, add the FolderUp icon and link
if (folderPath != Request.ApplicationPath.ToString())
{
rowItem = new TableRow();
cellItemIcon = new TableCell();
cellItemLink = new TableCell();
linkItem = new HyperLink();
imgItemIcon = new System.Web.UI.WebControls.Image();

// create the cell with the FolderUp icon
imgItemIcon.ImageUrl = "./Images/ParentFolder.gif";
cellItemIcon.Controls.Add(imgItemIcon);
cellItemIcon.HorizontalAlign = HorizontalAlign.Right;

// add the link that points to the parent directory
linkItem.Text = " ...";
int lastSlashIndex = folderPath.LastIndexOf("/");
location = folderPath.Substring(0,lastSlashIndex);
if (location.Length==0)
location = Request.ApplicationPath.ToString();
linkItem.NavigateUrl = "BrowseFiles.aspx?Folder=" + location;
linkItem.ApplyStyle(styleLink);
cellItemLink.Controls.Add(linkItem); // add the cells to the new row
rowItem.Cells.Add(cellItemIcon);
rowItem.Cells.Add(cellItemLink);
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());
rowItem.Cells.Add(new TableCell());

// add the row to the table
rowItem.ApplyStyle(styleFolderRow);
FoldersAndFiles.Rows.Add(rowItem);
} // add all the child directories first
foreach (DirectoryInfo childDir in childDirs)
{
rowItem = new TableRow();
cellItemLink = new TableCell();
linkItem = new HyperLink();
cellItemIcon = new TableCell();
checkItem = new CheckBox();
imgItemIcon = new System.Web.UI.WebControls.Image();
cellSize = new TableCell();
cellOperations = new TableCell();
linkRename = new HyperLink();
cellCreated = new TableCell();
cellLastModified = new TableCell();
cellAttributes = new TableCell();
labelAttributes = new Label();
linkSetAttribs = new HyperLink();

// create the link that points to this sub-directory
linkItem.Text = childDir.Name;
location = folderPath;
if (location.EndsWith("/"))
location += childDir.Name;
else
location += "/" + childDir.Name;
linkItem.NavigateUrl = "BrowseFiles.aspx?Folder=" + location;
linkItem.ApplyStyle(styleLink);
cellItemLink.Controls.Add(linkItem);

// set the cell that displays the item's size
cellSize.Text = FormatSize(GetDirectorySize(childDir.FullName)) + "  ";
cellSize.HorizontalAlign = HorizontalAlign.Right; // set the created and last modified date
cellCreated.Text = String.Format("{0:MM/dd/yy hh:mm tt}", childDir.CreationTime);
cellLastModified.Text = String.Format("{0:MM/dd/yy hh:mm tt}", childDir.LastWriteTime);

解决方案 »

  1.   


    // add the checkbox, and store the directory path as an attribute
    // in addition set an attribute that states that this item is not a file (this info
    // will be used later by the procedures that copy/move the selected items)
    checkItem.Attributes["Path"] = location;
    checkItem.Attributes["IsFile"] = "false";
    cellItemIcon.Controls.Add(checkItem); // add the icon with the closed folder
    imgItemIcon.ImageUrl = "./Images/ClosedFolder.gif";
    cellItemIcon.Controls.Add(imgItemIcon);
    cellItemIcon.HorizontalAlign = HorizontalAlign.Right; // add the Rename link. The 'D' before the file location will be used to determine
    // if the path identifies a file or a directory
    linkRename.Text = "<img src=\"./Images/Rename.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"更名\">";
    linkRename.NavigateUrl = "javascript:Rename('D" + location + "');";
    cellOperations.Controls.Add(linkRename); // set the attributes cell: the description label and the icon link to modify them
    labelAttributes.Text = GetAttributesDescription(childDir.Attributes); 
    labelAttributes.Font.Name = "Courier";
    linkSetAttribs.Text = "<img src=\"./Images/Edit.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"编辑属性\">";
    linkSetAttribs.NavigateUrl = "javascript:SetAttributes('" + location + "');";
    cellAttributes.Controls.Add(labelAttributes);
    cellAttributes.Controls.Add(linkSetAttribs); // add the cells to the new row
    rowItem.Cells.Add(cellItemIcon);
    rowItem.Cells.Add(cellItemLink);
    rowItem.Cells.Add(new TableCell());
    rowItem.Cells.Add(cellOperations);
    rowItem.Cells.Add(cellAttributes);
    rowItem.Cells.Add(cellSize);
    rowItem.Cells.Add(cellCreated);
    rowItem.Cells.Add(cellLastModified);

    // add the new row to the table
    rowItem.ApplyStyle(styleFolderRow);
    FoldersAndFiles.Rows.Add(rowItem);
    } // now add each child file
    foreach (FileInfo childFile in childFiles)
    {
    rowItem = new TableRow();
    cellItemLink = new TableCell();
    linkItem = new HyperLink();
    cellItemIcon = new TableCell();
    checkItem = new CheckBox();
    imgItemIcon = new System.Web.UI.WebControls.Image();
    cellDownload = new TableCell();
    linkDownload = new HyperLink();
    cellSize = new TableCell();
    cellOperations = new TableCell();
    linkRename = new HyperLink();
    cellCreated = new TableCell();
    cellLastModified = new TableCell();
    cellAttributes = new TableCell();
    labelAttributes = new Label();
    linkSetAttribs = new HyperLink();
    int extIndex;

    // create and add the link that points to this file, and open it in a new window
    linkItem.Text = childFile.Name;
    location = folderPath;
    if (location.EndsWith("/"))
    location += childFile.Name;
    else
    location += "/" + childFile.Name;
    linkItem.NavigateUrl = location;
    linkItem.Target = "_blank";
    linkItem.ApplyStyle(styleLink);
    cellItemLink.Controls.Add(linkItem); // add the link to download the file
    linkDownload.Text = "<img src=\"./Images/Download.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"下载\">";
    linkDownload.NavigateUrl = "Download.aspx?File=" + location;
    cellDownload.Controls.Add(linkDownload); // set the cell that displays the item's size
    cellSize.Text = FormatSize(childFile.Length) + "&nbsp;&nbsp;";
    cellSize.HorizontalAlign = HorizontalAlign.Right;

    // set the created and last modified date
    cellCreated.Text = String.Format("{0:MM/dd/yy hh:mm tt}", childFile.CreationTime);
    cellLastModified.Text = String.Format("{0:MM/dd/yy hh:mm tt}", childFile.LastWriteTime); // add the Rename link. The 'F' before the file location will be used to determine
    // if the path identifies a file or a directory
    linkRename.Text = "<img src=\"./Images/Rename.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"更名\">";
    linkRename.NavigateUrl = "javascript:Rename('F" + location + "');";
    cellOperations.Controls.Add(linkRename);

    // if this file is detected as a text file (basing on its extensions)
    // and the file is not read only or a system file, add an image link to edit it
    extIndex = Array.IndexOf(textExtensions, childFile.Extension.ToLower());
    if (extIndex > -1 && 
    (childFile.Attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly &&
    (childFile.Attributes & FileAttributes.System) != FileAttributes.System)
    {
    HyperLink linkEditFile = new HyperLink();
    linkEditFile.Text = "<img src=\"./Images/Write.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"编辑文件\">";
    linkEditFile.NavigateUrl = "EditFile.aspx?File=" + location;
    cellOperations.Controls.Add(linkEditFile);
    } // search the extension in the array, and in case show the respective icon
    // if not found add a general icon for unknown files
    extIndex = Array.IndexOf(extensions, childFile.Extension.ToLower());
    if (extIndex > -1)
    imgItemIcon.ImageUrl = "./Images/" + childFile.Extension.Substring(1) + ".gif";
    else
    imgItemIcon.ImageUrl = "./Images/unknown.gif";

    // set the checkbox and add the item's path and type (file) as 
    // it's done above for child directories
    checkItem.Attributes["Path"] = location;
    checkItem.Attributes["IsFile"] = "true";
    cellItemIcon.Controls.Add(checkItem);
    cellItemIcon.Controls.Add(imgItemIcon);
    cellItemIcon.HorizontalAlign = HorizontalAlign.Right; // set the attributes cell: the description label and the icon link to modify them
    labelAttributes.Text = GetAttributesDescription(childFile.Attributes); 
    labelAttributes.Font.Name = "Courier";
    linkSetAttribs.Text = "<img src=\"./Images/Edit.gif\" border=\"0\" height=\"16\" width=\"16\" Alt=\"编辑属性\">";
    linkSetAttribs.NavigateUrl = "javascript:SetAttributes('" + location + "');";
    cellAttributes.Controls.Add(labelAttributes);
    cellAttributes.Controls.Add(linkSetAttribs); // add the cells to the new row
    rowItem.Cells.Add(cellItemIcon);
    rowItem.Cells.Add(cellItemLink);
    rowItem.Cells.Add(cellDownload);
    rowItem.Cells.Add(cellOperations);
    rowItem.Cells.Add(cellAttributes);
    rowItem.Cells.Add(cellSize);
    rowItem.Cells.Add(cellCreated);
    rowItem.Cells.Add(cellLastModified); // add the new row to the table
    rowItem.ApplyStyle(styleFileRow);
    FoldersAndFiles.Rows.Add(rowItem);
    }
    }
      

  2.   

    2、我用的数据库中存储图片路径的方法来给Image控件绑定的:
    <asp:Image id="Image" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %>' Width="192" Visible='<%# DataBinder.Eval(Container.DataItem, "Visible") %>' >
    </asp:Image>
      

  3.   

    <INPUT id="file" type="file" name="File1" runat="server">