Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload a File to a Database? 1

Status
Not open for further replies.
Nov 21, 2000
26
0
0
US
How do I allow a user to "attach" a file (a MS Word File) for example to a program and save that file to my MS SQL 7Database.

Here is my senario. I have a table of Projects which contains information about a project. There is another table called Project_Files which contains a project_id (which matches the project_id of the parent project) and and image field called Project_File. I want the user to be able to browse their hard drive for a file, and then "attach" it to the program. When they hit Save I want the file to be saved into the image field in my database.
Then I want other users to be able to open that form and access that file for themselves to view. I know that this can not be all that tough, and I must just be an idiot for not being able to figure it out...

HELP PLEASE!
Steve
 
If I were you, I would not physically store the file IN the database. I would copy the file to the server (into a predefined directory) and save a link to the file in your database - ie a title to the document being the "link" - and in another field hold the path of the document (which the user will not see).
Simon
 
I actaully thought about that. And the problem is that are in a remote office (without a VPN) and the application is designed to work over the internet (connecting to SQL via TCP/IP not Named Pipes).

The two power users of the application (the ones that will be sharing these files for the most part) are in different physical offices. So there is not a commen server for them to share.

Steve
 
The common server will be the web server that the pages are fed from ...........
Simon
 
This isn't a web application. This is a Visual Basic 6 Application.
 
On a form;
set up a drive list box
set up a directory list box
set up a file list box
lET THE USER select the file they want using this set
of list boxes.
one the user has selected the file he/she wishes you can
open the file and read it and do anything with the contents
record by record.

Here is some of the code I used:

' read the file
Open sDir & "\fruit.ini" For Input As #1 Len = 80
' Read thru ini file.
Do While Not EOF(1) ' Loop until end of file.
Readini ' Read fruit.ini file.
If EOF(1) Then
Ctr = 0
End If
Loop
Close #1 ' Close file.
Private Sub Readini()
Dim J As Integer
On Error Resume Next
If EOF(1) Then Exit Sub
J = 0
Do Until EOF(1)
Input #1, Temp
If LCase(Mid(Temp, 1, 13)) = "databasename=" Then
DBNam = Mid(Temp, 14, Len(Temp) - 13)
End If
If LCase(Mid(Temp, 1, 10)) = "directory=" Then
DBDrive = Mid(Temp, 11, 1)
DBdir = Mid(Temp, 11, Len(Temp) - 10)
End If
If LCase(Mid(Temp, 1, 11)) = "campheader=" Then
DBHdr = Mid(Temp, 12, Len(Temp) - 10)
End If
If LCase(Mid(Temp, 1, 7)) = "userid=" Then
iniUserID(J) = Mid(Temp, 8, Len(Temp) - 7)
End If
If LCase(Mid(Temp, 1, 7)) = "passwd=" Then
iniUserPassWd(J) = Mid(Temp, 8, Len(Temp) - 6)
J = J + 1
End If
Loop
End Sub


"Manage drive, directory, and file list boxes

Private Sub drvDriveList_Change()
dirDirList.Path = drvDriveList.Drive
End Sub

Private Sub dirDirList_Change()
filFileList.Path = dirDirList.Path
End Sub

Private Sub filFileList_Click()
Dim I As Integer
If Right(filFileList.Path, 1) <> &quot;\&quot; Then
txtfilebaklod.Text = filFileList.Path &amp; &quot;\&quot; &amp; filFileList.FileName
Else
txtfilebaklod.Text = filFileList.Path &amp; filFileList.FileName
End If
I = InStr(UCase(txtfilebaklod.Text), &quot;DOC&quot;)
If I > 0 Then
FileType = &quot;DOC&quot;
'cmdLoadCpy.Enabled = True
cmdbaklod.Enabled = False
cmbCatLoaded.Clear
LoadcmbCatLoaded
cmbSheet.Clear
lblFileType.Caption = &quot; Word File Name &quot;
Exit Sub
Else
lblFileType.Caption = &quot; Excel File Name &quot;
FileType = &quot;XLS&quot;
End If
If txtfilebaklod.Text <> &quot;&quot; Then
cmdbaklod.Enabled = True
'cmdLoadCpy.Enabled = False
CkForSheets
End If
End Sub

RayMan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top