Sorry. I was on vacation up near the artic circle for awhile (really!). Here is the code for the Button2_Click event:
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs(Server.MapPath("~\Files\" & FileUpload1.FileName.ToString()))
Label1.Text = "<b>File Successfully Uploaded!</b><br />"
SqlDataSource2.DeleteParameters.Add("DeleteDocumentName", FileUpload1.FileName.ToString())
SqlDataSource2.Delete()
SqlDataSource2.InsertParameters.Add("DocumentName", FileUpload1.FileName.ToString())
SqlDataSource2.InsertParameters.Add("DateInput", DateTime.Now.ToString())
SqlDataSource2.Insert()
Catch ex As Exception
Label1.Text = "ERROR IN UPLOADING: " & ex.Message.ToString()
Finally
TextBox2.Text = ""
End Try
End If
End Sub
Here is the code for the entire page:
<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Untitled Page" MaintainScrollPositionOnPostback="true" %>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
SqlDataSource1.Insert()
TextBox1.Text = ""
CheckBox1.Checked = False
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs(Server.MapPath("~\Files\" & FileUpload1.FileName.ToString()))
Label1.Text = "<b>File Successfully Uploaded!</b><br />"
SqlDataSource2.DeleteParameters.Add("DeleteDocumentName", FileUpload1.FileName.ToString())
SqlDataSource2.Delete()
SqlDataSource2.InsertParameters.Add("DocumentName", FileUpload1.FileName.ToString())
SqlDataSource2.InsertParameters.Add("DateInput", DateTime.Now.ToString())
SqlDataSource2.Insert()
Catch ex As Exception
Label1.Text = "ERROR IN UPLOADING: " & ex.Message.ToString()
Finally
TextBox2.Text = ""
End Try
End If
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="body">
<div class="fullwidth">
<h2>File Category System</h2>
<p>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="SqlDataSource1" EmptyDataText="There are no categories present." Width="100%">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:CheckBoxField DataField="IsPublic" HeaderText="IsPublic" SortExpression="IsPublic" />
</Columns>
</asp:GridView>
<p>
<strong><span style="text-decoration: underline">Add a New Category</span></strong></p>
<p>
Category Name:<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></p>
<p>
<asp:CheckBox ID="CheckBox1" runat="server" Text="Check if category is public" /> </p>
<p>
<asp:Button ID="Button1" runat="server" Text="Add Category" OnClick="Button1_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>" DeleteCommand="DELETE FROM [DocumentCategories] WHERE [CategoryID] = @original_CategoryID" InsertCommand="INSERT INTO [DocumentCategories] ([CategoryName], [IsPublic]) VALUES (@CategoryName, @IsPublic)" SelectCommand="SELECT * FROM [DocumentCategories]" UpdateCommand="UPDATE [DocumentCategories] SET [CategoryName] = @CategoryName, [IsPublic] = @IsPublic WHERE [CategoryID] = @original_CategoryID">
<DeleteParameters>
<asp:Parameter Name="original_CategoryID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="IsPublic" Type="Boolean" />
<asp:Parameter Name="original_CategoryID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter Name="CategoryName" Type="String" ControlID="TextBox1" />
<asp:ControlParameter Name="IsPublic" Type="Boolean" ControlID="CheckBox1" />
</InsertParameters>
</asp:SqlDataSource>
</p>
</div>
<div class="fullwidth">
<h2>File Management System</h2>
<p>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="DocumentID" DataSourceID="SqlDataSource2"
EmptyDataText="There are no files present." Width="100%">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="DocumentID" HeaderText="DocumentID" InsertVisible="False"
ReadOnly="True" SortExpression="DocumentID" />
<asp:BoundField DataField="DocumentName" HeaderText="DocumentName" SortExpression="DocumentName" ReadOnly="True" />
<asp:BoundField DataField="DateInput" HeaderText="DateInput" SortExpression="DateInput" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
<asp:BoundField DataField="DocumentCategory" HeaderText="DocumentCategory" SortExpression="DocumentCategory" />
<asp:CheckBoxField DataField="TopDoc" HeaderText="TopDoc" SortExpression="TopDoc" />
</Columns>
</asp:GridView>
</p>
<p>
<strong><span style="text-decoration: underline">Add a New File</span></strong></p>
<p>
Select Category:<br />
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="CategoryName" DataValueField="CategoryID">
</asp:DropDownList></p>
<p>
File Comments:<br />
<asp:TextBox ID="TextBox2" runat="server" Width="350px"></asp:TextBox></p>
<p>
Show up on Top-Document List?
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Selected="True" Value="false">No</asp:ListItem>
</asp:RadioButtonList></p>
<p>
File to Upload:<br />
<asp:FileUpload ID="FileUpload1" runat="server" Width="350px" /></p>
<p>
<asp:Button ID="Button2" runat="server" Text="Upload File" OnClick="Button2_Click" /> </p>
<p>
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
DeleteCommand="DELETE FROM [Documents] WHERE [DocumentID] = @original_DocumentID"
InsertCommand="INSERT INTO [Documents] ([DocumentName], [DateInput], [Comments], [DocumentCategory], [TopDoc]) VALUES (@DocumentName, @DateInput, @Comments, @DocumentCategory, @TopDoc)"
SelectCommand="SELECT * FROM [Documents]" UpdateCommand="UPDATE [Documents] SET [DocumentName] = @DocumentName, [DateInput] = @DateInput, [Comments] = @Comments, [DocumentCategory] = @DocumentCategory, [TopDoc] = @TopDoc WHERE [DocumentID] = @original_DocumentID">
<DeleteParameters>
<asp:Parameter Name="original_DocumentID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="DocumentName" Type="String" />
<asp:Parameter Name="DateInput" Type="DateTime" />
<asp:Parameter Name="Comments" Type="String" />
<asp:Parameter Name="DocumentCategory" Type="Int32" />
<asp:Parameter Name="TopDoc" Type="Boolean" />
<asp:Parameter Name="original_DocumentID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter Name="Comments" Type="String" ControlID="TextBox2" />
<asp:ControlParameter Name="DocumentCategory" Type="Int32" ControlID="DropDownList1" PropertyName="SelectedValue" />
<asp:ControlParameter Name="TopDoc" Type="Boolean" ControlID="RadioButtonList1" PropertyName="SelectedValue" />
</InsertParameters>
</asp:SqlDataSource>
</p>
</div>
</div>
</asp:Content>
HTH, Bill Evjen