Append uploaded file name with dynamic form field

First let me say I'm new to coding, so forgive my improper naming, I think I've used names that make sense.

Here's my question, I have a form for uploading multiple images that uses a WebHandler class and this part works perfect for uploading the files to a predetermined location on my web server. What I would like to do is to append the uploaded image file name dynamically with the last name of the submitter.

I've tried many things, but I think the Handler class isn't getting the information from the regular code behind and trying to add the handler code into the code behind doesn't allow me to upload multiple image. Any suggestions? Here's all my code, hope I did this right!

Handler code
<%@ WebHandler Language="VB" Class="UploadVB" %>
 
Imports System
Imports System.Web
Imports System.IO
 
Public Class UploadVB : Implements IHttpHandler
   
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest


        Dim postedFile As HttpPostedFile = context.Request.Files("Filedata")
 
        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 & "\") + filename)
        context.Response.Write((tempPath & "/") + filename)
        context.Response.StatusCode = 200
		
		
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 
End Class

Open in new window


Regular Code Behind

Partial Class _Default
    Inherits System.Web.UI.Page
    'Public WithEvents startUploadLink As UserControl
	


       Protected Sub UploadSubmit(ByVal sender As Object, ByVal e As System.EventArgs) 
         If Page.IsValid Then
			Dim new_fname = ValidateInputForDB(fName.Text)
			Dim new_lname = ValidateInputForDB(lName.Text)
			'Dim new_email = ValidateInputForDB(email.Text)
			Dim new_FileUpload1 As FileUpload = DirectCast(Form1.FindControl("FileUpload1"), FileUpload)



		
		Dim strSQL As String
				
		strSQL	= 			"INSERT INTO artist_assets (fName, lName, FileUpload1)"				
				
        strSQL = strSQL & "VALUES ('" & new_fname & "','" & new_lname & "','" & new_FileUpload1.FileName  & "')"
 
 				call InsertUpdate(strSQL)	
    End If
	End Sub
     'more stuff below for connecting with database  
	End Class		

Open in new window


Web page with form
<%@ Page Language="VB" AutoEventWireup="true"  CodeFile="TriggerUpload.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Uploadify Example for .NET</title>
	<link href="css/default.css" rel="stylesheet" type="text/css" />
	<link href="css/uploadify.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="scripts/swfobject.js"></script>
	<script type="text/javascript" src="scripts/jquery.uploadify.v2.1.0.min.js"></script> 
    
    <script type="text/javascript">
	function ClientSideClick(myButton) {
	// Client side validation
		if (typeof (Page_ClientValidate) == 'function') {
		if (Page_ClientValidate() == false)
		{ return false; }
		}

		if (Page_IsValid) {

		myButton.disabled =

		true;
		myButton.className = "btn-inactive";
		myButton.value = "processing..."; 
		}

		else {

		}

		return true;
		
		}
		</script>
    
</head>
<body style='background:black;'>
<div id='main'>
        <form id="form1" runat="server">
         <script type="text/javascript">
function u(o){
  o.value=o.value.toUpperCase();
}</script>
        <asp:Label ID="labelMsg" EnableViewState="False" Runat="server"/><br>
			
           <div class="firsname"> First Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="fName" TabIndex="1" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox" /><asp:RequiredFieldValidator ID="valifName" Runat="server" ControlToValidate="fName" Display="Dynamic" Font-Size="XX-Small" 
		ErrorMessage="* First name required">
		 </asp:RequiredFieldValidator></div>
         
          <div class="lastname"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="lName"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  /><asp:RequiredFieldValidator ID="valilName" Runat="server" ControlToValidate="lName" Display="Dynamic" Font-Size="XX-Small" 
		ErrorMessage="* Last name required">
		 </asp:RequiredFieldValidator>
</div>
                    
         
            <div class="demo">
			
                <asp:FileUpload ID="FileUpload1" runat="server" />
				
				<br />
				<a href="#" id="startUploadLink" onclick="startUploadLink">Start Upload</a>&nbsp; |&nbsp;
				<a href="#" id="clearQueueLink">Clear</a> 

            </div>
            
             <div style="clear:left; padding-top:10px;margin-bottom:15px;"><asp:Button ID="btnUploadSubmit" Text="Submit" OnClick="UploadSubmit" onclientclick="ClientSideClick(this)"  UseSubmitBehavior="False" runat="server" class="green button"  Width="150px"  TabIndex="100"/></div>
                        
                      <asp:Label ID="lblResponse" runat="server" EnableViewState="False"></asp:Label>
          
          
        </form>
</div>
</body>
</html>
<script type = "text/javascript">

	$(document).ready( function() 
	{ 
		$("#<%=FileUpload1.ClientID%>").uploadify({
		'uploader'       : 'scripts/uploadify.swf',
		'script'         : 'UploadVB.ashx',
		'cancelImg'      : 'images/cancel.png',
		'folder'         : '/survey/uploads/uploads',
		'multi'          : true
		});
		
		$("#startUploadLink").click( function()
		{			
			$('#<%=FileUpload1.ClientID%>').uploadifyUpload();
			return false;
		});
		
		$("#clearQueueLink").click( function()
		{
			$("#<%=FileUpload1.ClientID%>").uploadifyClearQueue();							
			return false;			
		}); 

	});

</script> 

Open in new window

ellementalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guru_samiCommented:
So want to append the lastname to the filename before it's stored in the filesytem or you are considering when doing the db insert?
0
ellementalAuthor Commented:
I would prefer to append the file name with the last name before it's stored in the file system. If I can do that, I don't mind if the name isn't stored in the db.
0
guru_samiCommented:
You might want to store the lastname in the Session and grab it in the handler.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

ellementalAuthor Commented:
I've tried the following but it's still not adding the last name to the file name. To clarify, the way this page works is that the user first browses and adds their images which in effect saves them to the server I believe, because my actual submit button only saves the other items in my form to the db. I can't name both subs the same thing, but somehow calling both at the same time may be key.

Anyway, here is what I have so far for the Handler file. I'm calling the session variable as you suggested...

<%@ WebHandler Language="VB" Class="UploadVB" %>
 
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.SessionState
 
Public Class UploadVB : Implements IHttpHandler, IRequiresSessionState 
   
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest


        Dim postedFile As HttpPostedFile = context.Request.Files("Filedata")
 
        Dim lastname As sessionValue =     System.Web.HttpContext.Current.Session("lName")

		 
        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 & "\" & lastname & "_") + filename)
        context.Response.Write((tempPath & "/") + filename)
        context.Response.StatusCode = 200
		
		
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 
End Class

Open in new window


And here is  the regular code behind with the Session variable declared, but maybe this isn't the right way to do it?

Imports System
Imports System.Threading
Imports System.Web.UI.WebControls
Imports AjaxControlToolkit
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Text.RegularExpressions
Imports System.Net
Imports System.IO
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.Mail
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.SessionState

Partial Class _Default
    Inherits System.Web.UI.Page
    'Public WithEvents startUploadLink As UserControl
	
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

	Session("lName") = Server.HtmlEncode(lName.Text)
End Sub


       Protected Sub UploadSubmit(ByVal sender As Object, ByVal e As System.EventArgs) 
	 
	     If Page.IsValid Then
			Dim new_fname = ValidateInputForDB(fName.Text)
			Dim new_lname = ValidateInputForDB(lName.Text)
			'Dim new_email = ValidateInputForDB(email.Text)
			'Dim new_FileUpload1 As FileUpload = DirectCast(Form1.FindControl("FileUpload1"), FileUpload)
			Dim new_video1 = ValidateInputForDB(video1.Text)
			Dim new_video2 = ValidateInputForDB(video2.Text)
			Dim new_video3 = ValidateInputForDB(video3.Text)
			Dim new_video4 = ValidateInputForDB(video4.Text)
			Dim new_video5 = ValidateInputForDB(video5.Text)
			Dim new_video6 = ValidateInputForDB(video6.Text)	
			Dim new_video7 = ValidateInputForDB(video7.Text)	
			Dim new_video8 = ValidateInputForDB(video8.Text)	
			Dim new_video9 = ValidateInputForDB(video9.Text)	



		
		Dim strSQL As String
				
		strSQL	= 			"INSERT INTO artist_assets (fName, lName, video1, video2, video3, video4, video5, video6, video7, video8, video9)"				
				
        strSQL = strSQL & "VALUES ('" & new_fname & "','" & new_lname & "','" & new_video1 & "','" & new_video2 & "','" & new_video3 & "','" & new_video4 & "','" & new_video5 & "','" & new_video6 & "','" & new_video7 & "','" & new_video8 & "','" & new_video9 & "')"
 
 				call InsertUpdate(strSQL)	
    End If
	End Sub

     'more stuff below for connecting with database  
			
End Class

Open in new window


I don't think I changed the form, but I'm including it again below. I'm using the Uploadify script for this and I believe I can pass variables from the form to the Handler with the script noted at the very bottom of this page, but so far that hasn't worked either, just not doing it correctly.

<%@ Page Language="VB" AutoEventWireup="true"  CodeFile="TriggerUpload.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Uploadify Example for .NET</title>
	<link href="css/default.css" rel="stylesheet" type="text/css" />
	<link href="css/uploadify.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="scripts/swfobject.js"></script>
	<script type="text/javascript" src="scripts/jquery.uploadify.v2.1.0.min.js"></script> 
    
    <script type="text/javascript">
	function ClientSideClick(myButton) {
	// Client side validation
		if (typeof (Page_ClientValidate) == 'function') {
		if (Page_ClientValidate() == false)
		{ return false; }
		}

		if (Page_IsValid) {

		myButton.disabled =

		true;
		myButton.className = "btn-inactive";
		myButton.value = "processing..."; 
		}

		else {

		}

		return true;
		
		}
		</script>
    
</head>
<body style='background:black;'>
<div id='main'>
        <form id="form1" runat="server">
         <script type="text/javascript">
function u(o){
  o.value=o.value.toUpperCase();
}</script>
        <asp:Label ID="labelMsg" EnableViewState="False" Runat="server"/><br>
			
           <div class="firstname"> First Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="fName" TabIndex="1" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox" /><asp:RequiredFieldValidator ID="valifName" Runat="server" ControlToValidate="fName" Display="Dynamic" Font-Size="XX-Small" 
		ErrorMessage="* First name required">
		 </asp:RequiredFieldValidator></div>
         
          <div class="lastname"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="lName"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  /><asp:RequiredFieldValidator ID="valilName" Runat="server" ControlToValidate="lName" Display="Dynamic" Font-Size="XX-Small" 
		ErrorMessage="* Last name required">
		 </asp:RequiredFieldValidator>
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video1"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video2"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video3"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video4"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video5"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video6"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video7"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video8"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
<div class="video"> Last Name:<font color="#999999" class="percent_blue">*</font>  <asp:TextBox ID="video9"  TabIndex="2" Height="20px" Width="150px" runat="server" onblur="u(this)" CssClass="regTextBox"  />
</div>
                    
         
            <div class="demo">
			
                <asp:FileUpload ID="FileUpload1" runat="server" />
				
				<br />
				<a href="#" id="startUploadLink" onclick="startUploadLink">Start Upload</a>&nbsp; |&nbsp;
				<a href="#" id="clearQueueLink">Clear</a> 

            </div>
            
             <div style="clear:left; padding-top:10px;margin-bottom:15px;"><asp:Button ID="btnUploadSubmit" Text="Submit" OnClick="UploadSubmit" onclientclick="ClientSideClick(this)"  UseSubmitBehavior="False" runat="server" class="green button"  Width="150px"  TabIndex="100"/></div>
                        
                      <asp:Label ID="lblResponse" runat="server" EnableViewState="False"></asp:Label>
          
          
        </form>
</div>
</body>
</html>
<script type = "text/javascript">

	$(document).ready( function() 
	{ 
		$("#<%=FileUpload1.ClientID%>").uploadify({
		'uploader'       : 'scripts/uploadify.swf',
		'script'         : 'UploadVB.ashx',
		'cancelImg'      : 'images/cancel.png',
		'folder'         : '/survey/uploads/uploads/',
		'multi'          : true,
		'method'   : 'post',
    	'formData' : { 'lastname' : '<%=Request.Form("lName")%>' }
		});
		
		$("#startUploadLink").click( function()
		{			
			$('#<%=FileUpload1.ClientID%>').uploadifyUpload();
			return false;
		});
		
		$("#clearQueueLink").click( function()
		{
			$("#<%=FileUpload1.ClientID%>").uploadifyClearQueue();							
			return false;			
		}); 

	});

</script> 

Open in new window


Thank you for any suggestions, I think the session state was the right direction, but I'm not sure that I did it correctly.
0
ellementalAuthor Commented:
So I sort of got this working, but the Handler isn't getting the session variable before it uploads the image to the server... it IS getting the session variable after the upload, so the next image uploaded does have the appended file name. I'm close, but need some help with getting the session to the Handler before the Handler does the first upload and then I think I know how to destroy the session once the entire submit process is completed.

Here's my new Handler file:

<%@ WebHandler Language="VB" Class="UploadVB" %>
 
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.SessionState
 
Public Class UploadVB : Implements IHttpHandler, IRequiresSessionState 
   
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest


        Dim postedFile As HttpPostedFile = context.Request.Files("Filedata")
 
        Dim lastname As String =     context.Current.Session("LastName")

		 
        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 & "\" & lastname & "_") + filename)
        context.Response.Write((tempPath & "/") + filename)
        context.Response.StatusCode = 200
		
		
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 
End Class

Open in new window



Here's my code behind file:

Imports System
Imports System.Threading
Imports System.Web.UI.WebControls
Imports AjaxControlToolkit
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Text.RegularExpressions
Imports System.Net
Imports System.IO
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.Mail
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.SessionState

Partial Class _Default
    Inherits System.Web.UI.Page
    'Public WithEvents startUploadLink As UserControl
	
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim LastName = ValidateInputForDB(lName.Text)
If LastName <> "" Then
	Session("LastName") = LastName
End If
End Sub


       Protected Sub UploadSubmit(ByVal sender As Object, ByVal e As System.EventArgs) 
	 
	     If Page.IsValid Then
			Dim new_fname = ValidateInputForDB(fName.Text)
			Dim new_lname = ValidateInputForDB(lName.Text)
			'Dim new_email = ValidateInputForDB(email.Text)
			'Dim new_FileUpload1 As FileUpload = DirectCast(Form1.FindControl("FileUpload1"), FileUpload)
			Dim new_video1 = ValidateInputForDB(video1.Text)
			Dim new_video2 = ValidateInputForDB(video2.Text)
			Dim new_video3 = ValidateInputForDB(video3.Text)
			Dim new_video4 = ValidateInputForDB(video4.Text)
			Dim new_video5 = ValidateInputForDB(video5.Text)
			Dim new_video6 = ValidateInputForDB(video6.Text)	
			Dim new_video7 = ValidateInputForDB(video7.Text)	
			Dim new_video8 = ValidateInputForDB(video8.Text)	
			Dim new_video9 = ValidateInputForDB(video9.Text)	



		
		Dim strSQL As String
				
		strSQL	= 			"INSERT INTO artist_assets (fName, lName, video1, video2, video3, video4, video5, video6, video7, video8, video9)"				
				
        strSQL = strSQL & "VALUES ('" & new_fname & "','" & new_lname & "','" & new_video1 & "','" & new_video2 & "','" & new_video3 & "','" & new_video4 & "','" & new_video5 & "','" & new_video6 & "','" & new_video7 & "','" & new_video8 & "','" & new_video9 & "')"
 
 				call InsertUpdate(strSQL)	
    End If
	End Sub

     'more stuff below for connecting with database  
			
 End Class

Open in new window


The form stayed the same so won't insert it here.
0
guru_samiCommented:
Can you set the breakpoint to see if your Session is set before your handler code is executed.
I see Uploadify allows passing formData. So you might want to check this.
0
ellementalAuthor Commented:
I did see that Uploadify allows passing of formData. I've been searching their forum for hours looking for a vb example.

Here's what I have in the uploadify section which should be the same for vb or c#
      'formData' : { "lastname" : "<%=lName.Text%>" }      

Here's what was used in the Handler for the C# example you pointed me to:

string id = context.Request.Form[1];

and here's what I've tried:

Dim lastname As String =    context.Request.Form("lastname")

Dim lastname As String =    context.Request.Form[lastname]

Dim lastname As String =    context.Request.Form[1]

Dim lastname As String =    context.Request.Form.Value("lastname")

none of these work.

the second one doesn't give an error, but also doesn't append the file name. If you have thoughts on how to request that variable in the handler using vb let me know.

Regarding break points to see if the session variable is set, I haven't tried this yet, but I'm certain it's not set before the handler code is executed. It does finally receiving it, as I mentioned because if I reset the form and upload another image, this image contains the session from the last upload and appends the file name. So the session is set and stored after the first image upload. I just can't figure out how to set the session prior to the handler execution. I don't know actually know how to do the break points, but I'll read up on it and see if i can figure it out.

thanks again for your suggestions.
0
ellementalAuthor Commented:
Can I set breakpoints without using Visual Studio? I'm hand coding all this.
0
guru_samiCommented:
I think you might want to try the latest version of uploadify.
I used jquery 1.9.1

I tried this and it worked. Note some options are changed.
 $("#<%=FileUpload1.ClientID%>").uploadify({
        'swf': 'scripts/uploadify.swf',
        'cancelImg': 'images/cancel.png',
        'buttonText': 'Browse Files',
        'uploader': 'Upload.ashx',
        'folder': 'uploads',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'multi': true,
        'auto': false,
        'formData': { 'lastname': '<%=lblName.Text%>' }
        });

<a href="javascript:$('#<%=FileUpload1.ClientID%>').uploadify('upload')">Start Upload</a>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Label ID="lblName" runat="server" Text="test"></asp:Label>

//In .ashx
Dim lastname As String =    context.Request("lastname")

Open in new window

0
ellementalAuthor Commented:
I downloaded uploadify files again and updated the uploadify js (it's now v2.2) and I'm using the same 1.9.1 jquery as you, but I'm getting a 405 error with this code and no images upload to the server.

javascript:
$("#<%=FileUpload1.ClientID%>").uploadify({
            'uploader'       : 'scripts/uploadify.swf',
            'script'         : 'UploadVB.ashx',
            'cancelImg'      : 'images/cancel.png',
            'folder'         : '/survey/uploads/uploads/',
            'buttonText': 'Browse Files',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'multi': true,
        'auto': false,
        'formData': { 'lastname': '<%=lblName.Text%>' }
            });


Link for upload:
                  
<a href="javascript:$('#<%=FileUpload1.ClientID%>').uploadify('upload')">Start Upload</a>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Label ID="lblName" runat="server" Text="test"></asp:Label>

ashx file:

Dim lastname As String =     context.Request("lastname")


I see how this could work, it would have appended the file name with "test" yes? But not sure where I've went wrong that I'm getting the 405 error. Do you see something I did wrong?
0
guru_samiCommented:
This is different...
'swf'       : 'scripts/uploadify.swf',
'uploader'         : 'UploadVB.ashx',

Open in new window

0
ellementalAuthor Commented:
I wasn't sure what you meant by the latest version of uploadify... so I just purchased the HTML5 version of uploadify called uploadifive. I couldn't get it to work at all, even to just upload images to the server without appending the filename.
0
guru_samiCommented:
I used the free Uploadify Version 3.2.1 for test.
http://www.uploadify.com/download/
0
ellementalAuthor Commented:
I switched this
'uploader'       : 'scripts/uploadify.swf',
'script'         : 'UploadVB.ashx',

to this
'swf'       :  'scripts/uploadify.swf',
'uploader'         : 'UploadVB.ashx',

and now nothing happens at all, not even a 405 error.

would you confirm the version of uploadify you're using?
0
guru_samiCommented:
I used the uploadify.swf and jquery.uploadify.min.js that came in that download.
It says: Uploadify v3.2.1 and SWFObject v2.2

Are you using IE 10? If so try in compatibility View or FireFox.
0
ellementalAuthor Commented:
So these variable were changed in the newer uploadify 3.2.1 min js file
what was uploader is now swf and what was script is now uploader,
which is probably why they're working for you. I did try this newer min version of js and still no love so something else is off.
0
guru_samiCommented:
Here is a sample I used. It's missing the .ashx as I was unable to upload here but yours should work fine.
MultipleFilesUpload.zip
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ellementalAuthor Commented:
We're now using the same jquery and uploadify.js

Here's my javascript:

<script type = "text/javascript">

      $(document).ready( function()
      {
            $("#<%=FileUpload1.ClientID%>").uploadify({
            'swf'       :  'scripts/uploadify.swf',
            'uploader'         : 'UploadVB.ashx',
            'cancelImg'      : 'images/cancel.png',
            'folder'         : '/survey/uploads/uploads/',
              'buttonText': 'Browse Files',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'multi': true,
        'auto': false,
          'formData' : { 'lastname': '<%=lblName.Text%>' }
            });
            
            

</script>

Here's my FileUpload1 area:

                        <a href="javascript:$('#<%=FileUpload1.ClientID%>').uploadify('upload')">Start Upload</a>
           <asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Label ID="lblName" runat="server" Text="test"></asp:Label>

I no longer even have the option to upload multiple images, the browse button went away.

I tried to put a link in here to the actual page, but don't see it... will try again
http://usa.mapexdrums.com/Survey/Uploads/TriggerUpload.aspx

0
guru_samiCommented:
There's a js error in your code. It's missing the });
<script type = "text/javascript">

	$(document).ready( function() 
	{ 
		$("#FileUpload1").uploadify({
		'swf'       :  'scripts/uploadify.swf',
		'uploader'         : 'UploadVB.ashx',
		'cancelImg'      : 'images/cancel.png',
		'folder'         : '/survey/uploads/uploads',
		  'buttonText': 'Browse Files',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'multi': true,
        'auto': false,
    	'formData' : { 'lastname': 'test' }
		});
		
	});	

</script> 

Open in new window

0
ellementalAuthor Commented:
just saw  your zip upload. I'll take a look in the morning and let you know if I can get this thing to work. Thanks for your perseverance!
0
ellementalAuthor Commented:
I used your exact files and I can get the static lblName text "guru" to append the image name, but I needed a dynamic field to append the image name, such as the users last name that they'll input into the form prior to upload. I though the uploadify formData field would pass any variable on the page to the Handler, but it's only doing it with the static text field you provided.

I needed to have a solution by today so if you don't have any other ideas I'll need to start from scratch with something else. Thanks again for your assistance. I'll award you points for your download file, though it didn't do what my original request was asking for, it did append the file name with predefined static text which someone might find useful.
0
ellementalAuthor Commented:
This answer didn't provide a solution to my request, but the expert made a very good attempt to assist me.
0
guru_samiCommented:
Here's how you can make the formData dynamic. You need to set formData in the onUploadStart as shown below.

<asp:TextBox ID="lastname" runat="server"></asp:TextBox>
 function() {
        $("#<%=FileUpload1.ClientID%>").uploadify({
        'swf': 'scripts/uploadify.swf',
        'cancelImg': 'images/cancel.png',
        'buttonText': 'Browse Files',
        'uploader': 'Upload.ashx',
        'folder': 'uploads',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'multi': true,
        'auto': false,
        //'formData': { 'lastname': '<%=lblName.Text%>' },
            'onUploadStart': function (file) {
                var lastname = $('#<%=lastname.ClientID%>').val();
                $("#<%=FileUpload1.ClientID%>").uploadify("settings", 'formData', { 'lastname': lastname });
            }
        });

Open in new window

0
ellementalAuthor Commented:
This WORKED!!! Thank you!

For the record, with <asp:TextBox ID="lName" ...  here's my code:

    function() {
        $("#<%=FileUpload1.ClientID%>").uploadify({
        'swf': 'scripts/uploadify.swf',
        'cancelImg': 'images/cancel.png',
        'buttonText': 'Browse Files',
        'uploader': 'UploadVB.ashx',
        'folder': '/Survey/uploads/uploads',
        'fileDesc': 'Image Files',
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'multi': true,
        'auto': false,
            'formData': { 'lastname': '<%=lName.Text%>' },
            'onUploadStart': function (file) {
                var lastname = $('#<%=lName.ClientID%>').val();
                $("#<%=FileUpload1.ClientID%>").uploadify("settings", 'formData', { 'lastname': lastname });
            }            
        });
   }
0
ellementalAuthor Commented:
One last note, I hadn't been trying your code with multiple images so once I did I realized it worked, but I had to hit the start upload link each time. To make all images in queue upload at once I added an * like so and it works like a charm!

    <a href="javascript:$('#<%=FileUpload1.ClientID%>').uploadify('upload', '*')">Start Upload</a>
0
guru_samiCommented:
Glad it's working as expected.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.