Hi
I need help to bind gridview after capture photo
i used upload file in gridview in second link but when i used in capture photo i got some error in webserver instanace shared
Upload files, save in folder and display in ASP.Net GridView with Download and Delete option
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function DeleteItem() {
if (confirm("Delete this Location?")) {
return true;
} else {
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th align="center"><u>Live Camera</u></th>
<th align="center"><u>Captured Picture</u></th>
</tr>
<tr>
<td>
<div id="webcam"></div>
</td>
<td>
<img id="imgCapture" /></td>
</tr>
<tr>
<td align="center">
<input type="button" id="btnCapture" value="Capture" />
</td>
<td align="center">
<input type="button" id="btnUpload" value="Upload" disabled="disabled" />
</td>
</tr>
<tr>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText="No files uploaded">
<Columns>
<asp:BoundField DataField="Text" HeaderText="File Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%# Eval("Value") %>' runat="server" OnClick="DownloadFile"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" Text="Delete" CommandArgument='<%# Eval("Value") %>' runat="server" OnClick="DeleteFile" OnClientClick="return DeleteItem();" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</tr>
</table>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="WebCam.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
Webcam.set({
width: 320,
height: 240,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach('#webcam');
$("#btnCapture").click(function () {
Webcam.snap(function (data_uri) {
$("#imgCapture")[0].src = data_uri;
$("#btnUpload").removeAttr("disabled");
});
});
$("#btnUpload").click(function () {
$.ajax({
type: "POST",
url: "VB.aspx/SaveCapturedImage",
data: "{data: '" + $("#imgCapture")[0].src + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) { }
});
});
});
</script>
</body>
</html>
<WebMethod()>
Public Shared Function SaveCapturedImage(ByVal data As String) As Boolean
''Dim fileName As String = DateTime.Now.ToString("dd-MM-yy hh-mm-ss")
Dim fileName As String = "Filename"
Dim folderPath As String = HttpContext.Current.Server.MapPath("~/Captures/")
'Check whether Directory (Folder) exists.
Dim fileimg As String = folderPath + fileName + ".jpg"
If File.Exists(fileimg) Then
'If Directory (Folder) does not exists. Create it.
Return False
Else
'Convert Base64 Encoded string to Byte Array.
Dim imageBytes() As Byte = Convert.FromBase64String(data.Split(",")(1))
'Save the Byte Array as Image File.
Dim filePath As String = HttpContext.Current.Server.MapPath(String.Format("~/Captures/{0}.jpg", fileName))
File.WriteAllBytes(filePath, imageBytes)
Return True
End If
End Function
Public Sub gvbind()
Response.Redirect(Request.Url.AbsoluteUri)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim filePaths() As String = Directory.GetFiles(Server.MapPath("~/Captures/"))
Dim files As List(Of ListItem) = New List(Of ListItem)
For Each filePath As String In filePaths
files.Add(New ListItem(Path.GetFileName(filePath), filePath))
Next
GridView1.DataSource = files
GridView1.DataBind()
End If
End Sub
Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim filePath As String = CType(sender, LinkButton).CommandArgument
Response.ContentType = ContentType
Response.AppendHeader("Content-Disposition", ("attachment; filename=" + Path.GetFileName(filePath)))
Response.WriteFile(filePath)
Response.End()
End Sub
Protected Sub DeleteFile(ByVal sender As Object, ByVal e As EventArgs)
Dim filePath As String = CType(sender, LinkButton).CommandArgument
File.Delete(filePath)
Response.Redirect(Request.Url.AbsoluteUri)
End Sub