Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Managed File Upload File Editor

11:25 am on Jun 21, 2010 (gmt 0)

New User

5+ Year Member

joined:Dec 4, 2009
votes: 0

My website using aspx pages, requires a method for an authorised editor to login and upload files, say meeting minutes, in order that they may subsequently be viewed or printed. I am using Mysql database for the diary and guestbook pages. I have searched several forums but canít seem to find any leads.
Can anyone help or point me in the right direction.
1:05 pm on June 21, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
votes: 0

A simple way to do this is to use the asp:FileUpload control to save the file to the File System on the server, saving only the (relative) path to the file in your MySQL database.
1:39 pm on June 21, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
votes: 0

Here's working code I am using on a page of mine.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs)
If (upImage.HasFile) Then
If (CheckFileType(upImage.FileName)) Then
Dim filePath As String = "~/media-manager/" & upImage.FileName
End If
End If
End Sub

Function CheckFileType(ByVal fileName As String) As Boolean
Dim ext As String = Path.GetExtension(fileName)
Select Case ext.ToLower()
Case ".gif"
Return True
Case ".png"
Return True
Case ".jpg"
Return True
Case ".jpeg"
Return True
Case ".pdf"
Return True
Case ".doc"
Return True
Case ".xls"
Return True
Case ".docx"
Return True
Case ".xlsx"
Return True

Case Else
lblError.Text = "Invalid File Extension"
Return False
End Select
End Function

Sub Page_PreRender()
Dim upFolder As String = MapPath("~/media-manager/")
Dim dir As New DirectoryInfo(upFolder)
dlstImages.DataSource = dir.GetFiles()
End Sub
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>FileUpload File</title>
<form id="form1" runat="server">

Text="Image File:"
Runat="server" Font-Names="Verdana" Font-Size="10pt" />

Runat="server" />

<br /><br />

Text="Upload File"
Runat="server" />
<asp:Label ID="lblError" runat="server" ForeColor="Red" Font-Bold="True" Font-Names="Verdana" Font-Size="10pt"></asp:Label><br />
<br />

<hr />

runat="server" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Font-Names="Verdana" Font-Size="8pt" GridLines="Both" Width="94%">
Picture/file:<br /><asp:Image ID="Image1"
ImageUrl='<%# Eval("Name", "~/media-manager/{0}") %>'

Runat="server" />
<br /> <br />
link: [yourwebsite...] Eval("Name") %>

<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedItemStyle BackColor="#738A9C" BorderColor="White" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />

4:29 pm on June 21, 2010 (gmt 0)

New User

5+ Year Member

joined:Dec 4, 2009
votes: 0

Thank you both for your response and help.I had provisionally tried the fileUpload control but considered it not appropriate,however I will revisit.
Thank you hal12b for the complete code which is very helpful. I will work on this issue and report progress.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members