In response to a post in the ASP.Net forums, here is a routine to upload a file to a document library.
Sub ProcessPostedFile(ByVal fileUpload As HtmlControls.HtmlInputFile)
Try
' get the filename and stream
Dim fn As String = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName)
Dim stm As System.IO.Stream = fileUpload.PostedFile.InputStream
Dim contents(CInt(stm.Length)) As Byte
stm.Read(contents, 0, CInt(stm.Length))
stm.Close()
' get the library path
Dim docLibPath As String = Configuration.ConfigurationSettings.AppSettings("DocUploadPath")
' first, get the site containing the library
Dim site As SPSite = New SPSite(docLibPath)
Dim web As SPWeb = site.OpenWeb
' then get the folder
Dim docFolder As SPFolder = web.GetFolder(docLibPath)
' delete the file if it exists
Dim docFile As SPFile
Try
docFile = docFolder.Files(fn)
Catch ex As Exception
End Try
If Not docFile Is Nothing Then
docFolder.Files.Delete(fn)
End If
' save the file
docFile = docFolder.Files.Add(fn, contents)
Catch ex As Exception
Context.Trace.Warn(ex.ToString)
End Try
End Sub