Thursday, September 30, 2004
Well as I thought I am unable to blog daily :((
The below code is used to upload a file on to a directory in web server, html file control is used with runat=server attribute to select a file from client system.
Dim fsInputFile As Stream = flUpload.PostedFile.InputStream
Dim fileLen As Integer = flUpload.PostedFile.ContentLength
intFileSize = fileLen
Dim bnryData(fileLen) As Byte
Dim objFile As File
Dim objDir As Directory
Dim objFileInfo As FileInfo
Dim strfileName, strFilePath, strbasePath, strNewFile As String
Dim intBytes, n As Integer
If flUpload.PostedFile.FileName.Length > 0 Then
strFilePath = flUpload.PostedFile.FileName
End If
objFileInfo = New FileInfo(strFilePath)
strfileName = objFileInfo.Name
strNewFile = Request.ServerVariables("APPL_PHYSICAL_PATH") & ConfigurationSettings.AppSettings("DocumentStorage") & "\" & strfileName
n = fsInputFile.Read(bnryData, 0, fileLen)
'Create the Directory if it does not exist on the web server
If Not objDir.Exists(Request.ServerVariables("APPL_PHYSICAL_PATH") & ConfigurationSettings.AppSettings("DocumentStorage")) Then
Try
objDir.CreateDirectory(ConfigurationSettings.AppSettings("DocumentStorage"))
Catch ex As UnauthorizedAccessException
Response.Write("You do not have permission to create the required directory")
Response.End()
Finally
End Try
End If
'write to file
WriteToFile(strNewFile, bnryData)
End If
Private Sub WriteToFile(ByVal strPath As String, ByRef Buffer As Byte())
'Open or create a file
Dim newFile As FileStream = New FileStream(strPath, FileMode.Create)
'Write data to the file
newFile.Write(Buffer, 0, Buffer.Length)
'Close file
newFile.Close()
End Sub
The below code is used to upload a file on to a directory in web server, html file control is used with runat=server attribute to select a file from client system.
Dim fsInputFile As Stream = flUpload.PostedFile.InputStream
Dim fileLen As Integer = flUpload.PostedFile.ContentLength
intFileSize = fileLen
Dim bnryData(fileLen) As Byte
Dim objFile As File
Dim objDir As Directory
Dim objFileInfo As FileInfo
Dim strfileName, strFilePath, strbasePath, strNewFile As String
Dim intBytes, n As Integer
If flUpload.PostedFile.FileName.Length > 0 Then
strFilePath = flUpload.PostedFile.FileName
End If
objFileInfo = New FileInfo(strFilePath)
strfileName = objFileInfo.Name
strNewFile = Request.ServerVariables("APPL_PHYSICAL_PATH") & ConfigurationSettings.AppSettings("DocumentStorage") & "\" & strfileName
n = fsInputFile.Read(bnryData, 0, fileLen)
'Create the Directory if it does not exist on the web server
If Not objDir.Exists(Request.ServerVariables("APPL_PHYSICAL_PATH") & ConfigurationSettings.AppSettings("DocumentStorage")) Then
Try
objDir.CreateDirectory(ConfigurationSettings.AppSettings("DocumentStorage"))
Catch ex As UnauthorizedAccessException
Response.Write("You do not have permission to create the required directory")
Response.End()
Finally
End Try
End If
'write to file
WriteToFile(strNewFile, bnryData)
End If
Private Sub WriteToFile(ByVal strPath As String, ByRef Buffer As Byte())
'Open or create a file
Dim newFile As FileStream = New FileStream(strPath, FileMode.Create)
'Write data to the file
newFile.Write(Buffer, 0, Buffer.Length)
'Close file
newFile.Close()
End Sub
Thursday, September 23, 2004
Today all of a sudden I decided to activate my blog, and successfully found my forgotten password and started what innumerable number of software guys are doing blogging :))
Well as I have thought, I would be blogging the day to day coding snippets, tips etc which I come across druing my programming, well forgot to mention, I am using vb.net, asp.net, sql 2000 and Access 2000 for this project so will restrain my self to these.
Well first Iam sharing a handy procedure to view the list of server variables, This I used today to get the server variable which will retreive the physical path.
Private Sub GetServerVariables()
strBuilder.Append("")
Dim item As Object
For Each Item In Request.ServerVariables
strBuilder.Append(item)
strBuilder.Append(Request.ServerVariables(item))
'append a break tag here this editor does not allow me to use a br tag UH!
Next
Response.Write(strBuilder)
End Sub
Well this code snippet will list all the server variables.
Well as I have thought, I would be blogging the day to day coding snippets, tips etc which I come across druing my programming, well forgot to mention, I am using vb.net, asp.net, sql 2000 and Access 2000 for this project so will restrain my self to these.
Well first Iam sharing a handy procedure to view the list of server variables, This I used today to get the server variable which will retreive the physical path.
Private Sub GetServerVariables()
strBuilder.Append("")
Dim item As Object
For Each Item In Request.ServerVariables
strBuilder.Append(item)
strBuilder.Append(Request.ServerVariables(item))
'append a break tag here this editor does not allow me to use a br tag UH!
Next
Response.Write(strBuilder)
End Sub
Well this code snippet will list all the server variables.