📄 publicsharefile.aspx.vb
字号:
Imports System.data
Imports System.io
Partial Class Share_PublicShareFile
Inherits WebDiskBasePage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then '放在Ispostback中解决 回发或回调参数无效的问题
'必须进行初始华,因为所有页面均使用该会话进行排序
Session("SortName") = "Name"
Session("SortAscending") = "yes"
FillGridView(False)
Else
Me.StatusMessage.Text = String.Empty
End If
End Sub
'SortName排序字段名;direction排序的方式即递增还是递减,"yes"表示递增,"no"表示递减;bFilter为真表示进行过滤;在 bFilter为真时,需要过滤表达式
Private Sub FillGridView(ByVal bFilter As Boolean, Optional ByVal strFilter As String = Nothing)
Dim ds As New DataSet
Dim tempGif As String
'将XML文件数据转化为GridView中合适的数据格式
ShareXmlServer.CheckShareFile(Data.C_ShareFileXmlMapPath, True)
ds = ShareXmlServer.GetDataSetByXml(Data.C_ShareFileXmlMapPath)
If IsNothing(ds) Then Return
'显示扩展名类型图标,在ds数据表中增加Extension,再根据FileName列设置Extension列的值
ds.Tables(0).Columns.Add(New DataColumn("Extension", System.Type.GetType("System.String")))
For Each row As DataRow In ds.Tables(0).Rows
tempGif = FileDirServer.GetGifByFileName(row("Name").ToString)
If File.Exists(Server.MapPath(tempGif)) Then
row("Extension") = tempGif
Else
row("Extension") = Data.C_smilefacegifMapPath
End If
Next
Dim dv As DataView = ds.Tables(0).DefaultView
If bFilter Then
dv.RowFilter = strFilter ' "EnableUser='" + Session("User") + "'"
End If
If Session("SortAscending") = "yes" Then
dv.Sort = Session("SortName") + " ASC"
Else
dv.Sort = Session("SortName") + " DESC"
End If
GridView1.DataSource = dv
GridView1.DataBind()
'设置girdview脚本为记录总数
Dim lblFooter As Label = CType(GridView1.FooterRow.FindControl("lblFooter"), Label)
lblFooter.Text &= ds.Tables(0).DefaultView.Count
ds = Nothing
End Sub
#Region "GridView控件事件"
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim location As String
Dim hy As HyperLink = CType(e.Row.FindControl("NameLink"), HyperLink)
Dim CurrentPath As String = CType(e.Row.FindControl("Path"), Literal).Text
location = Path.Combine(CurrentPath, hy.Text)
If File.Exists(location) Then 'location为文件
Dim EditLink As HyperLink = CType(e.Row.FindControl("EditLink"), HyperLink)
Dim fi As New FileInfo(location)
'判断是否是文本文件
If FileDirServer.IsTextFile(fi.Extension.ToLower, Server.MapPath(Data.C_TextExtendXmlMapPath)) Then
'EditLink.Visible = True
EditLink.NavigateUrl = "~/FileManager/EditFile.aspx?File=" & Server.UrlEncode(location) '对中文进行编码
End If
'设置是否有密码,根据Pwd为空,则checkbox为false
Dim chkPwd As CheckBox = CType(e.Row.FindControl("chkPwd"), CheckBox)
If CType(e.Row.FindControl("Pwd"), Literal).Text = String.Empty Then
chkPwd.Checked = False
Else
chkPwd.Checked = True
End If
End If
End If
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "down" Then
'验证密码是否正确
Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
Dim location As String
Dim User As String = CType(GridView1.Rows(Index).FindControl("User"), Literal).Text
Dim CurrentPath As String = CType(GridView1.Rows(Index).FindControl("Path"), Literal).Text
Dim Name As String = CType(GridView1.Rows(Index).FindControl("NameLink"), HyperLink).Text
location = Path.Combine(CurrentPath, Name)
Dim strPwd As String = CType(GridView1.Rows(Index).FindControl("Pwd"), Literal).Text
If IsNothing(strPwd) Or strPwd = String.Empty Then
Session("downpass") = True
Server.Transfer("~/FileManager/Download.aspx?File=" & Server.UrlEncode(location))
Else
If funcParam.Value = strPwd Then
funcParam.Value = String.Empty
Session("downpass") = True
StatusMessage.Text = ""
Server.Transfer("~/FileManager/Download.aspx?File=" & Server.UrlEncode(location))
Else
Session("downpass") = False
StatusMessage.Text = "密码错误,请重新输入"
End If
End If
ElseIf e.CommandName = "del" Then '根据用户名和文件名删除共享
Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
Dim location As String
Dim User As String = CType(GridView1.Rows(Index).FindControl("User"), Literal).Text
Dim CurrentPath As String = CType(GridView1.Rows(Index).FindControl("Path"), Literal).Text
Dim Name As String = CType(GridView1.Rows(Index).FindControl("NameLink"), HyperLink).Text
location = Path.Combine(CurrentPath, Name)
ShareXmlServer.DeleteXmlRowByUserAndName(Data.C_ShareFileXmlMapPath, User, Name)
FillGridView(False)
End If
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
FillGridView(False)
End Sub
'处理GridView的排序事件()
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
WebPageShare.GridViewSort(GridView1, e)
FillGridView(False)
End Sub
#End Region
'仅显示共享给我的文件
Protected Sub chkMe_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkMe.CheckedChanged
If chkMe.Checked Then
Dim strFilter As String = "EnableUser='" + Session("User") + "'"
FillGridView(True, strFilter)
Else
FillGridView(False)
End If
End Sub
'根据扩展名过滤
Protected Sub ibutExp_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibutExp.Click
If txtExp.Text <> String.Empty Then
Dim strFilter As String = "Name like '" + txtExp.Text + "'"
FillGridView(True, strFilter)
End If
End Sub
Protected Sub ibutFileName_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibutFileName.Click
If txtUser.Text <> String.Empty Then
Dim strFilter As String = "User='" + txtUser.Text + "'"
FillGridView(True, strFilter)
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -