473,289 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

How to store image in sesstion ?

Dear All,Here I am facing problem to store image.I am trying to store byte
array(image) in to session variable so at time of update I will got that
byte array and I do my update. here i am given following code so kindly help
out me. on Button Click Event---------------------------------
Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnUpload.Click
Try
' Dim fileUpload1 As FileUpload =
CType(Me.FindControl("fpPhoto"), FileUpload)
'Make sure a file has been successfully uploaded
If fpPhoto.PostedFile Is Nothing OrElse
String.IsNullOrEmpty(fpPhoto.PostedFile.FileName) OrElse
fpPhoto.PostedFile.InputStream Is Nothing Then
lblerror.Text = "Please Upload Valid picture file"
Exit Sub
End If
Session("Path") = fpPhoto.PostedFile.FileName.ToString
'Make sure we are dealing with a JPG or GIF file
Dim extension As String =
System.IO.Path.GetExtension(fpPhoto.PostedFile.Fil eName).ToLower()
Dim MIMEType As String = Nothing
Select Case extension
Case ".gif"
MIMEType = "image/gif"
Case ".jpg", ".jpeg", ".jpe"
MIMEType = "image/jpeg"
Case ".png"
MIMEType = "image/png"
Case Else
'Invalid file type uploaded
Label1.Text = "Not a Valid file format"

Exit Sub
End Select

ImgPhoto.ImageUrl = fpPhoto.PostedFile.FileName
'Connect to the database and insert a new record into Products
Dim imageBytes(fpPhoto.PostedFile.InputStream.Length) As Byte
fpPhoto.PostedFile.InputStream.Read(imageBytes, 0,
imageBytes.Length)
Photo = imageBytes

' Session("Photo") = Photo


Catch ex As Exception
Throw ex
End Try
End Sub
------------------------------
update called by following
---------------------------------
Photo = CType(Session("Photo"), Byte())
UpdatePH_ID(Session("PH_ID_NO"), Session("DistID"), Photo)
--------------------------------------------------------------

CLASS FILE
------------------------
-----------------------
member Variable
-----------------
Private mPhoto As Byte() = Nothing
---------------
Property
---------------------
Public Property Photo() As Byte()
Get
Return mPhoto
End Get
Set(ByVal Value() As Byte)
mPhoto = Value
End Set
End Property
--------------
function
---------------
Public Sub UpdatePH_ID(ByVal id As Integer, ByVal id1 As Integer, ByVal p As
Byte())
'Make the object of the class that is supporting this Web Service

'Make the dataset that is to be used thoughout here
Dim objParameter As New cParameter(ds)

'Make the objParameter ready for insert
getCollection(objParameter, 2, id, id1, p, False)
'Make the dataset ready by filling it
If objservices.UpdateSJEDPH_ID1PhotoData(ds) = 1 Then
MsgBox("Photo for the current document is updated!")
End If

End Sub
Private Sub getCollection(ByRef objParameter As cParameter, ByVal index
As Int16, ByVal id As Integer, ByVal id1 As Integer, ByVal p As Byte(),
Optional ByVal common As Boolean = False)
If IsNothing(objParameter) Then
objParameter = New cParameter(ds)
End If
'objParameter.CreateParameter(dsEntry, "UserID",
My.Application.UserInfo.UserID.ToString)
'objParameter.CreateParameter(dsEntry, "OfficeID",
My.Application.UserInfo.OfficeID.ToString)
'objParameter.CreateParameter(dsEntry, "RoleID",
My.Application.UserInfo.RoleID.ToString)

Dim param As SqlParameter() = New SqlParameter(2) {}

param(0) = New SqlClient.SqlParameter("@PH_ID_NO1", ID)
param(1) = New SqlClient.SqlParameter("@dist_cd", id1)
param(2) = New SqlClient.SqlParameter("@Photo", p)

Dim drEntryPage As DataRow
ds.Tables("Parameter").Columns.Add("Photo", GetType(Byte()))
ds.Tables("Parameter").Columns.Add("Thumb", GetType(Byte()))
drEntryPage = ds.Tables("Parameter").NewRow()
SetValue(drEntryPage)
ds.Tables("Parameter").Rows.Add(drEntryPage)

End Sub
Private Sub SetValue(ByRef drEntryPage As DataRow)
Try
With drEntryPage
'.Item("SrNo") = DBNull.Value
'.Item("DocumentID") = DBNull.Value
'.Item("DocumentRefID") = DBNull.Value
'.Item("PhotoThumbID") = strPK
.Item("PName") = "Photo"
.Item("PValue") = Photo
.Item("PType") = enmParameterType.Input
.Item("DBType") = SqlDbType.Image
.Item("Photo") = Photo

'.Item("UserID") = My.Application.UserInfo.UserID
'.Item("OfficeID") = My.Application.UserInfo.OfficeID
'.Item("RoleID") = My.Application.UserInfo.RoleID
End With
Catch ex As Exception
Throw ex
End Try
End Sub

----------------------
web services
-----------------------
<WebMethod()_
Public Function UpdateSJEDPH_ID1PhotoData(ByRef ds As DataSet) As
Integer
Dim param As SqlParameter() = Nothing
Dim id As Integer
Dim i As Integer
param = New SqlParameter(ds.Tables(0).Rows.Count - 1) {}
For i = 0 To ds.Tables("Parameter").Rows.Count - 1
If Not IsDBNull(ds.Tables(0).Rows(i).Item(1)) AndAlso
ds.Tables(0).Rows(i).Item("DBType").ToString = "Image" Then
param(i) = New
SqlParameter(ds.Tables(0).Rows(i).Item(0).ToString ,
ds.Tables(0).Rows(i).Item("Photo"))
Else
param(i) = New
SqlParameter(ds.Tables(0).Rows(i).Item(0).ToString ,
ds.Tables(0).Rows(i).Item(1))
End If
Next i
id = SqlHelper.ExecuteScalar(getConnectionString(),
CommandType.StoredProcedure, "UpdateSJEDPH_ID1PhotoData", param)
Return id
End Function
Jun 27 '08 #1
0 1691

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Karen Grube | last post by:
Hi! Each week, we receive a two-page PDF file from UPS along with a separate flat file (a CSV) The PDF file contains the overview of our weekly invoice and the CSV contains the details of each...
0
by: aish | last post by:
I'm working with asp.net c# web application. In my app. I used session variables, I don't want to expire sesstion until the user clicks the logout button.but my application after some time period...
10
by: Raghavendra RAV | last post by:
Hi, I need to store an image from a Graphics object(.NET) inside a xml data island. Anyone might have came accross or have an idea how to do this. Please share. Thanks & Regards, Raghu, CSS...
6
by: Rudy | last post by:
Hello all! I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky,...
5
by: moondaddy | last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into...
4
by: serge | last post by:
I was working on figuring out where a certain application was storing the multiple selection choices I was doing through the app. I finally figured out that they were being store in an IMAGE data...
1
by: nwebhosting | last post by:
Hello and thank you. Could you please help me with this.: i try to store images using the following code, and it just bring a blank screen. i being trying different things and i am not sure if...
0
by: wizardworkz | last post by:
Hello All! Having a bit of a problem combining php with javascript here. What I have is a store with images (There will be a smaller image of each item, and a larger image of each item, but I want...
2
by: Skiran | last post by:
I am handling a large-scale project entitled as MIS (Marketing information System). I am using Vb 6 as front end, Ms Access as back end and Crystal report 8 as reporting tool. 1) In the project i...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.