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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Images, etc in SQL Server

Status
Not open for further replies.

atruhoo

Programmer
Jan 8, 2003
131
US
I know this isn't recomended and I should just store path name but my users want me to look at it some before telling them no. reason being at times they will be disconnected from server (presentations, etc) and will have a trimmed down version of the DB existing on the laptop. Have been playing around with uploading images from asp.net page but have not been able to display the image, pretty sure am missing something and would appreciate any input from more experienced asp.net users (switching from windows to web apps). Here is the code I have so far.


Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click

'UpLoads documents to desktop
If Not (myFile.PostedFile Is Nothing) Then
'Logic to find the FileName (excluding the path)
Dim strFileNamePath As String = myFile.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1, StrReverse(strFileNamePath), "\")
Dim strFileNameOnly As String = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)

Dim Length As Integer = myFile.PostedFile.InputStream.Length

ReDim myPic(Length)

Dim Conn As New SqlConnection(strConn)

myFile.PostedFile.InputStream.Read(myPic, 0, Length)

Dim strSql As String = "INSERT INTO FileUploads(Image,FileName) VALUES ( '" & myPic(Length) & "' , '" & strFileNameOnly & "')"
Conn.Open()
Dim cmd As New SqlCommand(strSql, Conn)
cmd.ExecuteNonQuery()
Conn.Close()

'Save to desktop
'myFile.PostedFile.SaveAs("C:\Documents and Settings\rstacy\Desktop\" & strFileNameOnly)
'Label1.Text = "File Upload Success."
End If

End Sub

Thanks in advance for any help...who knows this code could be right and problem could be in displaying image but won't know without asking will I.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top