Hi I have a piece of Javascript that calls an HTTP Handler and can call it several times (its for uploadify multi image uploader if this helps). Whats the best way to count the number of times the javascript uses the HTTP Handler. Here is the code
<%@ WebHandler Language="VB" Class="UploadVB" %>
Imports System
Imports System.Web
Imports System.IO
Imports System.Data
Imports System.Web.Configuration
Imports System.Web.UI
Public Class UploadVB : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim postedFile As HttpPostedFile = context.Request.Files("Filedata")
Dim strStockID As String = context.Request.QueryString("stockID")
Dim savepath As String = ""
Dim tempPath As String = ""
tempPath = System.Configuration.ConfigurationManager.AppSettings("FolderPath")
savepath = context.Server.MapPath(tempPath)
Dim filename As String = postedFile.FileName
If Not Directory.Exists(savepath) Then
Directory.CreateDirectory(savepath)
End If
postedFile.SaveAs((savepath & "\") & strStockID & "_" & filename)
context.Response.Write((tempPath & "/") & strStockID & "_" & filename)
context.Response.StatusCode = 200
'' insert into DB
Dim cn As New SqlClient.SqlConnection(WebConfigurationManager.ConnectionStrings("cn").ConnectionString)
Dim cmd As New SqlClient.SqlCommand("INSERT INTO image_bank (stockID, imageFile, datetimestamp) VALUES (@stockID,@imageFile,@datetimestamp)", cn)
cmd.Parameters.AddWithValue("@stockID", strStockID)
cmd.Parameters.AddWithValue("@imageFile", strStockID & "_" & filename)
cmd.Parameters.AddWithValue("@datetimestamp", DateTime.Now)
Try
cn.Open()
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
cmd.Dispose()
cn.Close()
Catch ex As Exception
cn.Close()
End Try
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
leonaisse
Member
40 Points
78 Posts
Count
Jan 30, 2013 07:30 PM|LINK
Hi I have a piece of Javascript that calls an HTTP Handler and can call it several times (its for uploadify multi image uploader if this helps). Whats the best way to count the number of times the javascript uses the HTTP Handler. Here is the code
<script type="text/javascript"> $(function () { $(".dummy").uploadify({ 'swf': 'scripts/uploadify.swf', 'itemTemplate': '<div id="${fileID}" class="uploadify-queue-item">\ <div class="cancel">\ <a href="javascript:$(\'#${instanceID}\').uploadify(\'cancel\', \'${fileID}\')">X</a>\ </div>\ <span class="fileName">${fileName} (${fileSize})</span><span class="data"></span>\ </div>', 'buttonText': 'Browse Files', 'uploader': 'uploadVB.ashx?StockID=<%=request.querystring("stockID") %>', 'method': 'post', 'fileTypeDesc': 'Image Files', 'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png', 'multi': true, 'auto': true }); }); </script>and the handler is
<%@ WebHandler Language="VB" Class="UploadVB" %> Imports System Imports System.Web Imports System.IO Imports System.Data Imports System.Web.Configuration Imports System.Web.UI Public Class UploadVB : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim postedFile As HttpPostedFile = context.Request.Files("Filedata") Dim strStockID As String = context.Request.QueryString("stockID") Dim savepath As String = "" Dim tempPath As String = "" tempPath = System.Configuration.ConfigurationManager.AppSettings("FolderPath") savepath = context.Server.MapPath(tempPath) Dim filename As String = postedFile.FileName If Not Directory.Exists(savepath) Then Directory.CreateDirectory(savepath) End If postedFile.SaveAs((savepath & "\") & strStockID & "_" & filename) context.Response.Write((tempPath & "/") & strStockID & "_" & filename) context.Response.StatusCode = 200 '' insert into DB Dim cn As New SqlClient.SqlConnection(WebConfigurationManager.ConnectionStrings("cn").ConnectionString) Dim cmd As New SqlClient.SqlCommand("INSERT INTO image_bank (stockID, imageFile, datetimestamp) VALUES (@stockID,@imageFile,@datetimestamp)", cn) cmd.Parameters.AddWithValue("@stockID", strStockID) cmd.Parameters.AddWithValue("@imageFile", strStockID & "_" & filename) cmd.Parameters.AddWithValue("@datetimestamp", DateTime.Now) Try cn.Open() Dim rowsAffected As Integer = cmd.ExecuteNonQuery() cmd.Dispose() cn.Close() Catch ex As Exception cn.Close() End Try End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End ClassThanks in advance
leonaisse
leonaisse
Member
40 Points
78 Posts
Re: Count
Feb 20, 2013 08:00 PM|LINK
I just but a Count Select statement in the ashx - works fine