Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,


I am doing a sample registration page. I happened to use file upload control in 3 tier architecture. I googled it and checked got some understanding about it but still my queation is how to use in 3 tier. i mean the flow. and also in database. For example, What is the datatype for it, any help....appreciated.
Posted

I agree with Kumar from madras, but I would just like to explain the flow a bit more...

Ok so usually you would not insert the file into the database itself, but rather have a folder in your website (in Kumar's example Uploads). Then you would have a field in your database table that references to the file (e.g. nvarchar(500))...

Example (C#) if you have a Database with a table UserFiles it would have a field FilePath...

C#
//The path of your folder inside your website
string virtualPath = "~/Uploads/";
//To upload a file you need a physical path to the folder
string physicalPath = Server.MapPath(virtualPath);
//This ensures that the file name is unique
string fileName = GUID.NewGuid().ToString();
//Grab the extension of the file
string extension = System.IO.Path.GetExtension(fileUpload.FileName);

//Ok now to actually upload the file to the server...
fileUpload.SaveAs(System.IO.Path.Combine(physicalPath,fileName + extension));

//Now to save the path to the database you have to call your method which inserts data into the table I'm just going to use a example class called UserFiles and a static method InsertFile that takes the filepath and inserts it into the table
UserFiles.InsertFile(virtualPath+fileName+extension);


I just typed this of the top of my head, but Intellisense will help you out if I made any mistakes.
 
Share this answer
 
HI JACK

PLS FIND THE BELOW SAMPLE CODE YOU CAN GET SOME IDEA

VB
Dim Dt As New DataTable
            Dim MyCommand As OleDbDataAdapter
            Dim filename As String = Me.FileUpload1.PostedFile.FileName
            Dim isvalid As Boolean = False
            Dim validfilename As String = ".PDF";
            Dim ext As String = System.IO.Path.GetExtension(filename)
            If ext <> "." & validfilename Then
                isvalid = False
                Return Dt
                Exit Function
            Else
            End If
            Dim savepath As String = Server.MapPath("~/Uploads/")
            Me.FileUpload1.PostedFile.SaveAs(savepath & System.IO.Path.GetFileName(filename))
            Dim fileupload As String = savepath
            Dim uploadfile As String = Server.MapPath("~/Uploads/") + System.IO.Path.GetFileName(filename)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900