Imports System.Web.ServicesImports System.configurationImports System.io
_public class fileserver inherits system.web.services.Webservice
#Region "Web Services Designer Generated Code"
Public Sub new () mybase.new ()
'This Call is Required by the Web Services Designer. InitializationComponent ()
'Add Your Own Initialization Code After The InitializationComponent () Call End Sub
'Required by The Web Services Designer Private Components as System.comPonentModel.icontainer
'NOTE: The following procedure is required by the Web Services Designer' It can be modified using the Web Services Designer 'Do not modify it using the code editor Private Sub InitializeComponent () components =.. New system.componentmodel.container () End Sub
Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) 'CODEGEN: This procedure is required by the Web Services Designer' Do not modify it using the code editor If disposing Then If Not (components Is Nothing) Then components.Dispose () End. If endiff mybase.dispose (disposing) End Sub
#End region
Private Shared WebserverPath As String = ConfigurationSettings.AppSettings ("WebServerRootpath")
Public Enum FileExtensions HTM HTML ASP ASPX JPG GIF DLL EXE All End ENUM
Public Class FileInformation Public Name As String Public Size As Long Public CreadedDate As DateTime Public LastModified As DateTime Public LastAccess As DateTime Public FileType As String Public FileLocation As String Public FileContent As Byte () End Class _ public function Directoryexists (Byval Path AS String) AS Boolean DIM DI AS New DirectoryInfo (WebServerPath & Path) Return Di.exists End Function
_ Public Function FileExists (ByVal Path As String, ByVal FileName As String) As Boolean Dim di As DirectoryInfo Dim fi As FileInfo Try di = New DirectoryInfo (WebServerPath & Path) If Not di.Exists Then Return False Exit Function End If Dim afi As FileInfo () = di.GetFiles () For Each fi In afi If fi.Name = FileName Then Return True Exit For End If Next Catch Return False End Try
END FUNCTION
_ Public Function Browse (ByVal VirtualPath As String, ByVal FileExtension As FileExtensions) As FileInformation () Dim i As Integer Dim fi As FileInfo Dim aFiles As FileInformation () Dim mExtension As String Select Case FileExtension Case FileExtensions.asp mExtension = "asp" Case FileExtensions.aspx mExtension = "aspx" Case FileExtensions.gif mExtension = "gif" Case FileExtensions.htm mExtension = "htm" Case FileExtensions .html mextension = "html" case fileExtensions.jpg mextension = "jpg" case fileExtensions.dll Mextension = "DLL" case fileExtensions.exe mextension = "exe" case fileextensions.all mextension = "*" end SELEC T DIM DI AS New DirectoryInfo (WebServerPath & VirtualPath) DIM AFI As Fileinfo () = _ Di.Getfiles ("*." & Mextension) Redim preserve Afiles (Afi.Length - 1) for Each Fi In Afiles (i) = New fileinformation () AFILES (i) .Name = FI.NAME AFILES (i) .size = FI.LENGTH AFILES (i) .lastaccess = FI.lastaccesstime Afiles (i) .creadeddate = FI.CRETIONTIME AFILES (i) .lastmodified = FI.lastWrittime Afiles (i) .filetype = FI.EXTENSION AFILES (i) .filelocation =
fi.DirectoryName aFiles (i) .FileContent = ReadFile (WebServerPath & VirtualPath & "/" & fi.Name) i = 1 Next Return aFiles End Function _ Public Function getFile (Byval FileName As String) AS BYTE () Return Readfile (WebserverPath & VirtualPath & "& FileName) End Function
Private Shared Function ReadFile (ByVal FilePath As String) As Byte () Dim fs As FileStream Try 'Read file and return contents fs = File.Open (FilePath, FileMode.Open, FileAccess.Read) Dim lngLen As Long = fs.Length Dim abytBuffer (CInt (lngLen - 1)) As Byte fs.Read (abytBuffer, 0, CInt (lngLen)) Return abytBuffer Catch exp As Exception Return Nothing Finally If Not fs Is Nothing Then fs.Close () End If End Try End Function
_ Public Function UploadFile (ByVal VirtualPath As String, ByVal Name As String, ByVal Content As Byte ()) As Boolean Dim objFile As File, objStream As StreamWriter , objFstream As FileStream Try objFstream = File.Open (WebServerPath & VirtualPath & "/" & Name, FileMode.Create, FileAccess.Write) Dim lngLen As Long = Content.Length objFstream.Write (Content, 0, CInt (lngLen)) objFstream.Flush () objFstream.Close () Return True Catch exc As System.UnauthorizedAccessException Return False Catch exc As Exception Return False Finally If Not objFstream Is Nothing Then objFstream.Close () End If End Try End Function # Region "Helper Function" Public Function About () AS STRI ng 'Uses the StringWriter to build a string with carriage returns & line feeds to' return back to a calling client the Title, Version, and Description by 'reading Assembly meta-data originally entered in the AssemblyInfo.vb file' using the AssemblyInfo class Defined in The Same File.
Try Dim Sw as new system.io.stringwriter () Dim ainfo as new assemblyinfo ()
WITH SW .WRITELINE (ainfo.title) .writeline ("Version {0}", ainfo.version)) .writeline ("") .writeline ("") .writeline (ainfo.description) .writeline (") .Writeline (ainfo.codebase) End withdim strretval as string = sw.toString sw.close ()
Return Strretval Catch Exp As Exception Return Exp.Message End Try End Function # End Region
END CLASS