改了下VS里原来的FileUpload控件的SaveAs方法

ssy888 2008-07-11 05:17:45
更新了下VS里原来的FileUpload控件的SaveAs方法,把上传文件路井分为根和下一级,通过页面传递ID自动创建对应名称的子文件夹,如果主文件夹不存在,也自动创建。
明天到了公司再把按键,和ListBox加进去做个组合控件,只要页面或后台输入主路近,和子路进,直接点提交就完成,下面LixtBox显示当前文件夹下共有多少文件。后台cs(vb)文件不用再写任何代码.

Public Class RaboFileUpLoad
Inherits FileUpload
#Region "Properties"
Private m_BasePath As String
Private m_HttpBasePath As String
Private m_PlaceFiles As String
Private m_PlaceFilesDownload As String

Public Property BasePath() As String
Get
BasePath = m_BasePath
End Get
Set(ByVal value As String)
m_BasePath = value
End Set
End Property

Public Property PlaceFiles() As String '' sub folder path properties
Get
PlaceFiles = m_PlaceFiles
End Get
Set(ByVal value As String)
m_PlaceFiles = value
End Set
End Property
#End Region

#Region "Methods"
Public Overloads Sub SaveAs()
FolderExists(Me.BasePath)
FolderExists(Me.BasePath & Me.PlaceFiles)
If Me.FileName IsNot Nothing AndAlso Me.FileName.ToString <> "" Then
Me.SaveAs(Me.BasePath & Me.PlaceFiles & Me.FileName)
Me.Dispose()
End If
End Sub

Private Sub FolderExists(ByVal FolderPath As String)
Dim folder As New System.IO.DirectoryInfo(FolderPath)
If Not folder.Exists() Then
folder.Create()
End If
End Sub
#End Region

End Class
...全文
130 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssy888 2008-07-11
  • 打赏
  • 举报
回复
Imports Microsoft.VisualBasic
Imports Rabo.Services.PortalLibrary
Imports System.Data
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Control
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebControl

Public Class RaboFileUpload
Inherits WebControl
Implements INamingContainer

''' <summary>
''' Created 09-07-2008 senyan v1.0
''' This is a custom easy-mode file upload control, a link button mixed to simplify your work.
''' How to use:
''' 1. Call this control
''' 2. Set BasePath and PlaceFiles string in page_load event
''' e.g. Me.RaboFileUpload1.BasePath = "C:\Temp\"
''' Me.RaboFileUpload1.PlaceFiles = "Ticket_33\"
''' 3. run page, select a file, and then click upload button
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks> set child control default style, size, layout in CreateChildControls() method</remarks>
#Region "Properties"

Public Property BasePath() As String
Get
Return ViewState("BasePath")
End Get
Set(ByVal value As String)
ViewState("BasePath") = value
End Set
End Property

Public Property PlaceFiles() As String
Get
Return ViewState("PlaceFiles")
End Get
Set(ByVal value As String)
ViewState("PlaceFiles") = value
End Set
End Property

#End Region

#Region "Methods"
Protected Overrides Sub CreateChildControls()
Dim fu As New FileUpload
Dim bt As New LinkButton
bt.Text = "Upload"
Controls.Add(fu)
Controls.Add(bt)
AddHandler bt.Click, AddressOf Me.ButtonClicked
End Sub

Private Sub ButtonClicked(ByVal sender As Object, ByVal e As EventArgs)
Dim ChildFileUpload As FileUpload = CType(Me.Controls("0"), FileUpload)
Me.OnCheck(Me.BasePath, Me.PlaceFiles, ChildFileUpload)
End Sub

Private Sub OnCheck(ByVal BasePath As String, ByVal PlaceFiles As String, ByRef ChildFileUpload As FileUpload)
FolderExists(BasePath)
FolderExists(BasePath & PlaceFiles)
If ChildFileUpload.FileName IsNot Nothing AndAlso ChildFileUpload.FileName <> "" Then
ChildFileUpload.SaveAs(BasePath & PlaceFiles & ChildFileUpload.FileName)
ChildFileUpload.Dispose()
End If
End Sub

Private Sub FolderExists(ByVal FolderPath As String)
Dim folder As New System.IO.DirectoryInfo(FolderPath)
If Not folder.Exists() Then
folder.Create()
End If
End Sub
#End Region

End Class
dotnet东哥 2008-07-11
  • 打赏
  • 举报
回复
嗯!支持!

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧