OK, first since you are using a code behind that is where you should have put that code.
Your .aspx file is should look something like this.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Mangae Downloads.aspx.vb" Inherits="Admin_Mangae_Downloads" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Description<br />
<asp:TextBox ID="txtDescription" runat="server"></asp:TextBox><br />
Category<br />
<asp:TextBox ID="txtCategory" runat="server"></asp:TextBox><br />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>
</body>
</html>
Now your code behind should look like this
Imports System.IO
Partial Class Admin_Mangae_Downloads
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
DoUpload()
End Sub
Protected Sub DoUpload()
Dim SavePath As String = "~/"
Dim UploadFile As String = _
Server.MapPath(SavePath & FileUpload1.FileName)
Dim NoPath As String = Path.GetFileName(FileUpload1.FileName)
Try
InsertNewRecord(NoPath, GetFileSize(FileUpload1.FileName), txtDescription.Text, UploadFile, txtCategory.Text)
If FileUpload1.HasFile Then FileUpload1.PostedFile.SaveAs(UploadFile)
Catch ex As Exception
MsgBox("There was a problem: " & Err.Description)
End Try
End Sub
Public Sub InsertNewRecord(ByVal FileName As String, ByVal FileSize As Long, ByVal Description As String, ByVal FileURL As String, ByVal Category As String)
Dim sql As New SqlDataSource()
sql.ConnectionString = ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString()
sql.InsertCommandType = SqlDataSourceCommandType.Text
sql.InsertCommand = "Insert Into TableName (FileName, FileSize, Description, FileURL, Category) Values (@FileName, @FileSize, @Description, @FileURL, @Category)"
sql.InsertParameters.Add("FileName", FileName)
sql.InsertParameters.Add("FileSize", FileSize)
sql.InsertParameters.Add("Description", Description)
sql.InsertParameters.Add("FileURL", FileURL)
sql.InsertParameters.Add("Category", Category)
sql.Insert()
sql.Dispose()
End Sub
Protected Function GetFileSize(ByVal MyFile As String)
Dim nFileInfo As New FileInfo(Server.MapPath(MyFile))
Dim FileInBytes As Long = nFileInfo.Length
Dim FileInKB As Long = nFileInfo.Length / 1024
GetFileSize = FileInBytes
End Function
End Class
Try to get that working for now, should be able to simply copy paste code for each file.