Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
NET and MS
Access
An easy to setup and use, no-frills content management system with asp.net and MS Access. If you need to setup a
small site, or quickly add some pages to an existing site, or let someone else update pages on your website. This
simple system was the quick answer. This system can be a basic framework to build up a more advanced content
management system. Or you can integrate this into your existing website to update some pages quickly from your
web browser.
I'm rather new to .NET, trying to move my skills from classic ASP. So please let me know if you find things that
could have been done better, or if something isn't working right.
This basic content management system does not use any templates, and no HTML editors. This makes the design of
your pages completely up to you. It also has a bare bones file management system to go along with this, so you can
upload your images easily as well.
Once you have all the files copied into a folder somewhere in your website structure, and assuming you have
default.aspx and a "default page" in IIS. Then when you browse to the folder you should get the page that is set as
default within the CMS (Content Management System).
Open up include.aspx, this has the basic settings used with the system. This page will then be included in each file
within the system for "global" settings.
Note: your database and upload path should have read/write/delete permissions
The database is best located outside of your webroot for best security. There is no usernames or passwords stored
in the database, so this is not critical, but generally a good idea.
Sessions are used for security, so be sure that sessions are enabled on your web server for this app to work. The
following code is used to check for this session on the administration pages.
The code below will open up the database, look for a record matching the id of the querystring variable passed to it,
if no querystring value is passed, then it opens up the record that is marked as "home page". This enables you to
have a "default" page, that will be displayed.
While myReader.Read()
mydata = (myReader("pagedata").tostring)
End While
'close connections'
myReader.Close()
myConn.Close()
MyConn = Nothing
Else
Dim query As String = _
"Select pagedata FROM tblpages WHERE homepage = 1;"
Dim myConn As New OleDbConnection _
("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource & "")
Dim myCmd As OleDbCommand = New OleDbCommand(query, myConn)
myConn.Open()
Dim myReader As OleDbDataReader = myCmd.ExecuteReader()
While myReader.Read()
mydata = (myReader("pagedata").tostring)
End While
'close connections'
myReader.Close()
myConn.Close()
MyConn = Nothing
End if
End Sub
</script>
<%=mydata%>
A simple page list makes it easy to add or delete "pages" from your site. All pages are stored in the MS Access
database.
This code below basically loops through the database then uses repeater to display the data on the page. This page
also has links to create a new page, which will do a simple "insert" into the database. This list also lets you set which
page will be the "default" page as described earlier.
End Sub
</script>
<h3 class="myfont" title="visit www.basic-cms.com for updates">Basic CMS -
Page Management</h3>
<p><a href="list.aspx?newpage=1" title="click here to create a new page">
Create New Page</a></p>
<asp:Repeater id="tblpages" runat="server">
<HeaderTemplate>
<table border="1" cellspacing="0" cellpadding="4" bordercolor="#000000"
class="myfont">
<tr bgcolor="#b0c4de">
<th>ID</th>
<th>Page Description</th>
<th>Default</th>
<th>URL</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</HeaderTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#FFFFFF">
<td><%#Container.DataItem("id")%> </td>
<td><%#Container.DataItem("pagename")%> </td>
<td><a href="list.aspx?id=<%#Container.DataItem("id")%>&homepage=1"
title="Click to set as home page">
<%#Container.DataItem("homepage")%></a> </td>
<td><a href="default.aspx?id=<%#Container.DataItem("id")%>
" title="default.aspx?id=<%#Container.DataItem("id")%>"
target="_blank">default.aspx?id=<%#Container.DataItem("id")%></td>
<td><a href="edit.aspx?id=<%#Container.DataItem("id")%>"
title="Click to Edit">Edit</a> </td>
<td><a href="list.aspx?deleteid=<%#Container.DataItem("id")%>"
title="Delete!">Delete</a></td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr bgcolor="#f0f0f0">
<td><%#Container.DataItem("id")%> </td>
<td><%#Container.DataItem("pagename")%> </td>
<td><a href="list.aspx?id=<%#Container.DataItem("id")%>&homepage=1"
title="Click to set as home page">
<%#Container.DataItem("homepage")%></a> </td>
<td><a href="default.aspx?id=<%#Container.DataItem("id")%>"
title="default.aspx?id=<%#Container.DataItem("id")%>" target="_blank">
default.aspx?id=<%#Container.DataItem("id")%></td>
<td><a href="edit.aspx?id=<%#Container.DataItem("id")%>"
title="Click to Edit">Edit</a> </td>
<td><a href="list.aspx?deleteid=<%#Container.DataItem("id")%>"
title="Delete!"
onclick="return confirm('Are you sure you want to delete?')">Delete</a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Label Id="lblrcount" RunAt="server" CssClass="myfont"
ForeColor="#000000" font-size="12" />
<form runat="server">
<asp:Button Id="btnShowHelp" RunAt="server"
Text="Help" OnClick="btnHelp_OnClick" class="myfont"
title="click for basic help" />
</form>
The simple file manager used all .NET code, no 3rd parth components are required. This file manager will allow you
to upload files and delete files, as well as view what files are in the upload directory.
<%@ Page Language="vb" Debug=true ValidateRequest=false %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- #INCLUDE FILE="include.aspx" -->
<!-- #INCLUDE FILE="menu.aspx" -->
<html>
<head>
<title>File Manager</title>
<script runat="server" language="vb">
Sub Page_Load(sender As Object, e As EventArgs)
if session("loggedin") = "" then
response.redirect("login.aspx")
end if
show_files()
End Sub
Sub Show_files
Dim file As String
Me.ListBox1.Items.Clear()
Dim files() As String = Directory.GetFiles(uploadpath)
For Each file In files
Me.ListBox1.Items.Add(FileNameWithoutExtension(file))
Next
End Sub
FileName.InnerHtml = MyFile.PostedFile.FileName
FileContent.InnerHtml = MyFile.PostedFile.ContentType
FileSize.InnerHtml = MyFile.PostedFile.ContentLength
UploadDetails.visible = True
For the complete download of ALL code and files visit this site
This system is VERY basic yes, but sometimes simple and basic is better.
I'm rather new to .NET, trying to move my skills from classic ASP. So please let me know if you find things that
could have been done better, or if something isn't working right.