The following works for me. It is basically the whitepaper version with a modification to store the files in a "files" directory off of the web root.
1) Create a "files" directory off of the web root
2) Use the following to create the tables (you may need to modify it to specify the table owner - depending on your hosting company):
CREATE TABLE [DocumentCategories] (
[CategoryID] [int] IDENTITY (1, 1) NOT NULL ,
[CategoryName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[IsPublic] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [Documents] (
[DocumentID] [int] IDENTITY (1, 1) NOT NULL ,
[DocumentName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DateInput] [datetime] NULL ,
[Comments] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[DocumentCategory] [int] NULL ,
[TopDoc] [bit] NULL
) ON [PRIMARY]
GO
ALTER TABLE [DocumentCategories] ADD
CONSTRAINT [PK_DocumentCategories] PRIMARY KEY CLUSTERED
(
[CategoryID]
) ON [PRIMARY]
GO
ALTER TABLE [Documents] ADD
CONSTRAINT [PK_Documents] PRIMARY KEY CLUSTERED
(
[DocumentID]
) ON [PRIMARY]
GO
3) Here is the files.aspx page:
<%@ Page Language="C#" MasterPageFile="~/Default.master" Title="Files" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="body">
<div class="fullwidth">
<h2>File Categories</h2>
<p>Click on a category to see a list of available files.</p>
<p>
<asp:DataList ID="DataList1" runat="server" DataKeyField="CategoryID" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("CategoryID", @"Files.aspx?categoryid={0}") %>'
Text='<%# Eval("CategoryName") %>'></asp:HyperLink>
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
SelectCommand="SELECT * FROM [DocumentCategories] WHERE ([IsPublic] = @IsPublic) ORDER BY [CategoryName]">
<SelectParameters>
<asp:Parameter DefaultValue="True" Name="IsPublic" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
</p>
</div>
<div class="fullwidth">
<h2>Files</h2>
<p>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="DocumentID" Width="100%" DataSourceID="SqlDataSource2">
<Columns>
<asp:TemplateField HeaderText="Document Name" SortExpression="DocumentName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DocumentName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval("DocumentName", @"~\Files\{0}") %>'
Text='<%# Eval("DocumentName") %>' Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DateInput" HeaderText="Date Input" SortExpression="DateInput" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
SelectCommand="SELECT * FROM [Documents] WHERE ([DocumentCategory] = @DocumentCategory) ORDER BY [DateInput] DESC">
<SelectParameters>
<asp:QueryStringParameter Name="DocumentCategory" QueryStringField="categoryid" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</p>
</div>
</div>
</asp:Content>
4) And finally, here is files_admin.aspx:
<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Files Management" MaintainScrollPositionOnPostback="true" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
Protected Sub GridView2_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
'Since documents are not stored in the database, they must be deleted from
'the filesystem when the user clicks the delete button in the gridview
File.Delete(Server.MapPath("~\files\") & e.Values(0).ToString())
End Sub
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] = @CategoryID"
InsertCommand="INSERT INTO [DocumentCategories] ([CategoryName], [IsPublic]) VALUES (@CategoryName, @IsPublic)"
SelectCommand="SELECT * FROM [DocumentCategories]"
UpdateCommand="UPDATE [DocumentCategories] SET [CategoryName] = @CategoryName, [IsPublic] = @IsPublic WHERE [CategoryID] = @CategoryID">
<DeleteParameters>
<asp:Parameter Name="CategoryID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="IsPublic" Type="Boolean" />
<asp:Parameter Name="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"
OnRowDeleting="GridView2_RowDeleting" 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] = @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] = @DocumentID">
<DeleteParameters>
<asp:Parameter Name="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="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>