用一个HTML控件 叫File Field 就OK了
解决方案 »
- 关于DropDownList
- 打开新页面并传递多个参数??
- VS2010 ASP.NET项目,点击在浏览器中查看无任何反映
- 伪静态 页面里所有的链接都要改?
- 在Repeater 中 使用 CheckBox控件 无法触发OnChange事件
- 请问这段代码应该如何修改?
- 帮找个小错误,立刻给分!!!
- 在javascript里,通过showModalDialog传回数组,将这数组赋给一变量,调用该变量的construct时出错,请教高手,如何解决这个问题
- 是否支持ASP.NET的主机空间速度都比较慢,哪里提供的空间速度比较快?
- 大家好,怎么样在后台获取 前台的input type="text"的文本值(.net)!帮忙解决 谢谢
- 求救:使用非自带控件为什么提示“灾难性故障”?急!
- 问一下怎样从数据库中 把字段调出来 显示在TextBox中?
<html>
<head>
<meta name="GENERATOR" Content="ASP Express 2.1">
<title>Drives/Folders/Files</title>
<script language="VB" runat="server">
Dim sSystemDrives as String()
Dim intNumberOfDrives as Integer
Dim sDrive
Dim strParent As String
Dim sDriveList as string
Sub Page_Load(Source As Object, E As System.EventArgs)Dim drives As String() = Directory.GetLogicalDrives()
Dim count As Integer = drives.Length
Dim i As Integer
For i = 0 To count - 1
sDriveList += "<span class=""dobig""><a href=Files.aspx?d=" & drives(i) & " class='dobig'>" & _
drives(i) & " </a> </span> "
Next i
Literal1.text+=sDriveList
Literal1.text += "<hr>"if request.Querystring("d") <> "" then
Dim d as String
d=request.querystring("d")
GetFiles()
End If
End Sub Sub GetFiles() Try
Dim strDir As String = Request.QueryString("d")
strParent = strDir.Substring(0, strDir.LastIndexOf("\"))
'strParent += strParent.EndsWith(":") ? "\\" : ""
if strParent.endswith(":") then
strParent=strParent & "\"
End If
upLink.NavigateUrl = "files.aspx?d=" + strParent
txtCurrentDir.Text = "Address: <b>" + strDir + "</b>"
Dim DirInfo As New DirectoryInfo(strDir)
Dim subDirs As DirectoryInfo() = DirInfo.GetDirectories()
Dim Files As FileInfo() = DirInfo.GetFiles()
txtFileList.Text = "<table border=""0"" width=""50%"">"
Dim i As Integer
For i = 0 To subDirs.Length - 1
txtFileList.Text += "<tr><td><img src='images/folder.gif'><a href=""files.aspx?d=" & _
subDirs(i).Fullname & _
chr(34) &">" & subDirs(i).Name & "</a></td><td valign='bottom'>" & _
subDirs(i).LastWriteTime & "</td></tr>"
Next i
For i = 0 To Files.Length - 1
if right(Files(i).Name, 3) = "gif" or right(Files(i).Name, 3) = "jpg" then
txtFileList.Text += "<tr><td><img src='images/file.gif'><a href='" & _
strDir & "/" & Files(i).Name & "' target='_blank'>" & _
Files(i).Name & "</a></td><td valign='bottom'>" & _
Files(i).LastWriteTime & "</td></tr>"
else
txtFileList.Text += "<tr><td><img src='images/file.gif'>" & _
Files(i).Name & "</td><td valign='bottom'>" & _
Files(i).LastWriteTime & "</td></tr>"
End If Next i
txtFileList.Text += "</table>"
Catch
txtFileList.Text = "Error retrieving directory info - Check Drive (" & strParent & ")"
End TryEnd Sub</script><STYLE TYPE="text/css">
<!--
BODY {
font-family : Arial;
font-size : 10pt;
}
TD {
font-family : Arial;
font-size : 10pt;
}
.DoBig {
font-family : Verdana;
font-size : 12pt;
font-weight : bold;
}
-->
</STYLE>
</head>
<body>
<div align="center"><asp:Literal ID="literal1" text="<b>Drives:</b><br>" runat="server" /></div>
<form runat="server">
<asp:HyperLink id="upLink" runat="server" ImageUrl="images/up.gif"/>
<br/>
<asp:Label id="txtCurrentDir" Font-Name="MS Sans Serif" Font-Size="8pt" runat="server"/>
<br><br>
<asp:Label id="txtFileList" Font-Name="MS Sans Serif" Font-Size="8pt" runat="server"/>
</form>
</body>
</html>
FileInfo 獲得目錄内文件列表,並且能查看内容:
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then
const strDir = "d:\temp"
lblHeader.Text = "<b><u>File Listing for " & strDir & ":</u></b>"
Dim dirInfo as New DirectoryInfo(strDir) '取目錄
Dim aFiles as FileInfo() = dirInfo.GetFiles("*.*") '取目錄内文件列表
dlFileList.DataSource = aFiles
dlFileList.DataBind()
End If
End Sub
Sub dlFileList_Select(sender as Object, e as EventArgs) '打開指定文件
Dim strFilePath as String = dlFileList.DataKeys(dlFileList.SelectedItem.ItemIndex).ToString()
Dim objFileInfo as FileInfo = new FileInfo(strFilePath)
Dim objStream as StreamReader = objFileInfo.OpenText()
Dim strContents as String = objStream.ReadToEnd()
objStream.Close()
lblFileContents.Text = "<b>Contents of " & objFileInfo.Name & ":</b>" & _
"<xmp>" & vbCrLf & strContents & vbCrLf & "</xmp>"
' xmp 是爲了能顯示文本時候忽略html標簽
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:label id="lblHeader" runat="server" /><br> <asp:DataList runat="server" id="dlFileList"
OnSelectedIndexChanged="dlFileList_Select" DataKeyField="FullName" >
<ItemTemplate>
<li><%# DataBinder.Eval(Container.DataItem, "Name") %><br>
<font size=-1>
[<asp:linkbutton Text="View Contents" CommandName="Select" runat="server"/>] |
[<%# DataBinder.Eval(Container.DataItem, "Length") %> bytes]
</font>
<p>
</ItemTemplate>
</asp:DataList>
<p><hr><p>
<asp:label runat="server" id="lblFileContents" />
</form>
</body>
</html>
谢了。