View Single Post
  #1 (permalink)  
Old June 18th, 2006, 05:22 PM
GigaBear GigaBear is offline
Registered User
Join Date: Jun 2006
Location: Maassluis, , Netherlands.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Howto save a Filename uploaded file to db?

I'm trying to build an intranet on which users can, amongst other things, upload a file to present other users some info on their performance. This file will be stored on the server and other info (name, URL, description) will be stored in a database.

The upload part is going OK:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Uploaden KPI bestand" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If FileUpload1.HasFile Then
                FileUpload1.SaveAs("H:\\Visual websites\\Communicator\\KPI_bestanden\\" & FileUpload1.FileName)
                Label1.Text = "Het bestand " & FileUpload1.FileName & " is verstuurd."

            Catch ex As Exception
                Label1.Text = "FOUT: " & ex.Message.ToString()
            End Try
        End If

End Sub

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>Je wilt een bestand toevoegen / wijzigen aan de volgende KPI:</p>

    <asp:FileUpload ID="FileUpload1" runat="server" Style="position: relative; left: 7px;" /><br />
    <br />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="left: 31px;
        position: relative; top: 0px;" Text="Bestand versturen" /><br />
    <br />
    <asp:Label ID="Label1" runat="server" Style="left: 4px; position: relative; top: 0px"
The part I can't figure out is how to get the filename of the uploaded file in a database record, preferebly in one go with uploading.
Since it must be possible for the users to change the file when the performance data changes I have to provide the possibility to insert a new record (and upload a new file) and to update the record with a new filename.

Anyone any suggestions???
Reply With Quote