Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: Beginning ASP.NET Databases
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET Databases Also see the forum ASP Databases for more general discussions of ASP database issues not directly related to these books.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old July 22nd, 2003, 01:50 PM
Registered User
Join Date: Jun 2003
Location: Tustin, CA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET - C# Upload file to Database


In C# and ASP.NET:
I'm looking for a way to upload a binary file (Word Document, JPEG, etc) and store it to a Database (Access or SQL).
Then able to view the file in the clients browser or download it to the client machine.

I hope someone can point me to a book which explains this or can write a tutorial.

Thank you !!


Life to the fullest
Reply With Quote
  #2 (permalink)  
Old July 23rd, 2003, 01:13 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik Send a message via Skype™ to melvik

I hope this sample will help u!

<%@ Page debug="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
        <title>::: UPLOAD SAMPLE ::: </title>
        <script language="c#" runat="server">

            void Page_Load(Object sender, EventArgs e)
                if (Page.IsPostBack)

            System.Boolean SaveImages()
            System.Web.HttpFileCollection colFiles = System.Web.HttpContext.Current.Request.Files;
            System.Text.StringBuilder strMessage;
            strMessage = new System.Text.StringBuilder("Files Uploaded:<br><br>");
            System.Int32 intFileCntr;


                for (intFileCntr = 0; intFileCntr < colFiles.Count; intFileCntr++)

                    System.Web.HttpPostedFile objCurrentFile = colFiles.Get(intFileCntr);
                    System.String strCurrentFileName;
                    System.String strCurrentFileExtension;

                    strCurrentFileName = System.IO.Path.GetFileName(objCurrentFile.FileName );

                    if(strCurrentFileName != "")

                        strCurrentFileExtension = System.IO.Path.GetExtension(strCurrentFileName);

                        if (strCurrentFileExtension == ".gif" || strCurrentFileExtension == ".jpg")
                            objCurrentFile.SaveAs(Server.MapPath("books\\") + strCurrentFileName);

                            strMessage.Append(strCurrentFileName + " successfully uploaded.<BR>");
                            strMessage.Append(strCurrentFileName + " failed!! Only .gif and .jpg images allowed! <BR>");

                Label1.Text = strMessage.ToString();
                return true;
            catch (System.Exception Ex)
                Label1.Text = Ex.Message;
                return false;

            <form id="UPLOAD" method="post" encType="multipart/form-data" runat="server">
                <h3>Multiple File Upload Example</h3>
                <P><INPUT id="File1" type="file" size="50" name="File1" runat="server"></P>
                <P><INPUT id="File2" type="file" size="50" name="File2" runat="server"></P>
                <P><INPUT id="File3" type="file" size="50" name="File3" runat="server"></P>
                <P><INPUT id="File4" type="file" size="50" name="File4" runat="server"></P>
                <P><INPUT id="File5" type="file" size="50" name="File5" runat="server"></P>
                <P><STRONG>:: </STRONG>
                    <asp:linkbutton id="LinkButton1" runat="server" Font-Size="XX-Small" Font-Bold="True" Font-Names="Verdana">Upload Images</asp:linkbutton><STRONG>::
                    </STRONG><A id="LinkButton2" style="FONT-WEIGHT: bold; FONT-SIZE: xx-small; FONT-FAMILY: verdana" href="java script:document.forms[0].reset()">
                        Reset Form</A> <STRONG>::</STRONG></P>
<P><asp:label id="Label1" runat="server" Font-Size="XX-Small" Font-Bold="True" Font-Names="verdana" BorderColor="White" BorderStyle="None" Width="400px"></asp:label></P>
<asp:Label id=Label2 runat="server">Label</asp:Label></P>
<asp:Label id=Label3 runat="server">Label</asp:Label></P>

Hovik Melkomian.
Reply With Quote
  #3 (permalink)  
Old August 15th, 2007, 03:15 PM
Registered User
Join Date: Aug 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

I am new to all this and I want to use this c# upload utility asap.
So where should I copy-paste this code and how do I use it?
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Component for multiple file upload subhasps8 ASP.NET 1.0 and 1.1 Professional 1 June 22nd, 2007 07:43 AM
Filter File Types in ASP.NET File Upload ramuis78 ASP.NET 2.0 Basics 2 May 31st, 2007 11:50 AM
Asp.net upload Excel Column to Database Patrick19 VB.NET 0 April 18th, 2005 03:56 AM
file upload in ASP.net problem lpastor ADO.NET 1 September 15th, 2004 09:55 AM

All times are GMT -4. The time now is 06:32 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.