Tevin says:
Dim
Path
As
String
=
"~\C:\Desktop\images"
File.WriteAllBytes(Server.MapPath(Path & dtPhoto.Rows(i)(
"Name"
) &
".jpg"
), bytes)
Change with below code.
Dim filePth As String = "C:\Desktop\images\"
If Not Directory.Exists(filePth) Then
Directory.CreateDirectory(filePth)
End If
File.WriteAllBytes(filePth & dtPhoto.Rows(i)("Name") & ".jpg", bytes)
You need to verify the path exists or not before saving.
Updated code.
Protected Sub lnkbtnExport_Click(sender As Object, e As EventArgs)
For Each rpitem As RepeaterItem In rpEmployee.Items
Dim EmpID As Label = CType(rpitem.FindControl("lblID"), Label)
mLMS = New aplch(My.Settings.GuHR_Data)
Dim dtPhoto As DataTable = mLMS.GetEmployeePhoto(Convert.ToInt32(EmpID.Text))
For i As Integer = 0 To dtPhoto.Rows.Count - 1
Dim bytes As Byte() = CType(dtPhoto.Rows(i)("Photo"), Byte())
Dim filePth As String = "C:\Desktop\images\"
If Not Directory.Exists(filePth) Then
Directory.CreateDirectory(filePth)
End If
File.WriteAllBytes(filePth & dtPhoto.Rows(i)("Name") & ".jpg", bytes)
Next
Next
Dim strEmployee As String = txtSearchByEmployee.Text
Dim strClockNo As String = strEmployee.Substring(0, strEmployee.IndexOf(":"))
mLMS = New aplch(My.Settings.GuHR_Data)
Dim dt As DataTable = mLMS.FilterByReportToEmployee(strClockNo)
ExcelExport(dt)
End Sub