| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3092 人关注过本帖
标题:有这样一个业务需求,各位高手看如何用asp.net编码
只看楼主 加入收藏
fxy0214
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-10-13
收藏
得分:0 

我是用VB.NET写的,比较简单,7-s2是目录浏览的文件代码,7-s3是查看文件内容(只加了word文档/excel/jpg图片)的文件代码,

以下是7-s2.aspx的代码,其中e:\document是要浏览的文件目录:

Imports System.IO

Public Class _7_s2 Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 Dim dirobj As DirectoryInfo If Request.QueryString.Get("dir") = "" Then dirobj = New DirectoryInfo("e:\document") If dirobj.Exists = False Then Response.Write("该文件夹不存在") Else dispinfo("e:\document") End If Else dispinfo(HttpUtility.UrlDecode(Request.QueryString.Get("dir"))) End If

End Sub Private Sub dispinfo(ByVal pathstr As String) Dim dirobj As DirectoryInfo Dim arrstr() As DirectoryInfo Dim arrstr1() As FileInfo Dim i As Integer dirobj = New DirectoryInfo(pathstr) Response.Write("<center><h2>搜索指定文件夹中的全部内容<hr></h2></center>") Response.Write("您现在浏览的目录是:" & dirobj.FullName.ToString) Response.Write("<br>该目录创建时间为:" & dirobj.CreationTime.ToString) Response.Write("<br>最后修改时间为:" & dirobj.LastWriteTime.ToString & "<br>")

arrstr = dirobj.GetDirectories If arrstr.Length > 0 Then Response.Write("该目录下的子目录有:<br>") Response.Write("<table border='2' width='90%'>") For i = 0 To arrstr.Length - 1 Response.Write("<tr><td><a href='7-s2.aspx?dir=" & HttpUtility.UrlEncode(arrstr(i).FullName) & "'>" & arrstr(i).Name & "</a></td></tr>") Next Response.Write("</table>") End If

arrstr1 = dirobj.GetFiles

If arrstr1.Length > 0 Then Response.Write("该目录下的文件有:<br>") Response.Write("<table border='2' width='90%'>") For i = 0 To arrstr1.Length - 1 Response.Write("<tr><td><a href='7-s3.aspx?file=" & HttpUtility.UrlEncode(arrstr1(i).FullName) & "'>" & arrstr1(i).Name & "</a></td></tr>") Next Response.Write("</table>") End If End Sub End Class

7-s3.aspx文件的代码为:

Imports System.IO Public Class _7_s3 Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 Dim fileobj As FileInfo fileobj = New FileInfo(HttpUtility.UrlDecode(Request.QueryString.Get("file"))) Select Case LCase(fileobj.Extension) Case ".doc" Response.ContentType = "Application/msword" Case ".xls" Response.ContentType = "Application/msexcel" Case ".jpg" Response.ContentType = "image/JPEG" End Select

Response.WriteFile(HttpUtility.UrlDecode(Request.QueryString.Get("file"))) End Sub

End Class

2004-10-14 13:55
fxy0214
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-10-13
收藏
得分:0 
另外,查看文件内容还有一个简单的办法就是将文件夹直接放入站点文件夹内,通过虚拟路径直接链接到文件即可.
2004-10-14 13:58
jeiffel
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2004-10-12
收藏
得分:0 

fxy0214,谢谢你,我准备测试一下,非常感谢!!

另外,你说的虚拟目录的方法,我天生愚钝,能否详细点?

2004-10-18 14:03
fxy0214
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-10-13
收藏
得分:0 
有一点需要声明一下,EXCEL文档的contenttype我写错了,具体值我没记清,你可以到注册表中查看.xls的contenttype,或者到IIS中查看MIME类型
2004-10-18 21:44
fxy0214
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-10-13
收藏
得分:0 
至于转化成虚拟目录的方法,我觉得还不如这样简单,因为我也不知道有没有一个函数能把物理路径转化为虚拟路径,我用的是取字符串方式得到的虚拟路径。
2004-10-18 21:48
sondid
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-11-3
收藏
得分:0 

微软的sharepoint网站解决的就是这样一个问题

实现文件管理,文档管理

只是很简单的一些功能,做的已经很好了

如过需要简单的,你只要装一个sharepoint services就可以了,但是前提是要用2003的操作系统,因为这是2003内置的一个功能

2004-11-03 11:00
clgood
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2004-10-18
收藏
得分:0 
我记得在ASP里边有中间插件可以实现这个功能 !!呵呵!
2004-11-05 09:37
jeiffel
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2004-10-12
收藏
得分:0 
sondid 你说的sharepoint网站是怎么回事,sharepoint services如何装
2004-11-16 10:36
yanguan025
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2004-11-21
收藏
得分:0 

可以通过《添加引用》添加EXCEL和WORD的对象库

然后具体的操作参考。NET的帮助文档里面写的很清楚

2004-11-21 13:00
zilangdth
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2004-11-23
收藏
得分:0 

导入数据库,用SELECT检索出来不就行了

2004-11-23 13:54
快速回复:有这样一个业务需求,各位高手看如何用asp.net编码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026739 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved