flash and .net

Hi

I have the flash file

and I am submitting the values through flash

How can I get that value from flash to .net
KaranGuptaAsked:
Who is Participating?
 
Kelvin McDanielSr. Developer/ConsultantCommented:
I'll do you one better; here's what you need. This code assumes you're using C# v9.0 (in v3.5 of the .NET Framework); if you're not you'll need to exchange the varios "var" keywords with the appropriate types.
// ************************
// Code for the receiving MailProcessor.aspx page:
// ************************
 
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="MailProcessor.aspx.cs" Inherits="MailProcessor" %>
 
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        
            <asp:Label ID="lblResults" runat="server" Text="... to be processed ..." />
        
        </div>
    </form>
</body>
</html>
 
 
// ************************
// Code for the receiving MailProcessor.aspx.cs page:
// ************************
 
using System;
using System.Net.Mail;
using System.Text;
 
public partial class MailProcessor : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // This is for while you're proving Flash can post to this page
        var sb = new StringBuilder();
        sb.Append("<p>");
 
        foreach (var formVariable in Request.Form.Keys)
        {
            sb.Append(string.Format("{0}: {1}<br />", formVariable.ToString(), Request.Form[formVariable.ToString()]));
        }
 
        sb.Append("</p>");
        lblResults.Text = sb.ToString();
 
        // This is for when you're ready to actually send emails
        SendEmail();
    }
 
    private void SendEmail()
    {
        // This is for when you're ready to process messages
        // Create instance of main mail message class.
        var intendedRecipient = "whomever@yourchoice.com";
        var SMTPServer = "your email server address";
        var SMTPServerPort = 25; //"whatever is required; if it isn't remove this variable from line 46
        
        using (var mailMessage = new MailMessage(Request.Form["email"].Trim(), intendedRecipient))
        {
            //Configure mail mesage
 
            // 1. Set the From address with user input
            mailMessage.Subject = Request.Form["subject"].Trim();
            mailMessage.Body = "From " + Environment.NewLine + Request.Form["name"].Trim() + Environment.NewLine + Environment.NewLine 
                                + "Message:" + Environment.NewLine + Request.Form["message"].Trim();
 
            // 2. Specify if this is Text or HTML
            mailMessage.IsBodyHtml = false;
 
            // 3. Create an instance of the SmtpClient class for sending the email
            var smtpClient = new SmtpClient(SMTPServer, SMTPServerPort);
 
            // 4. Use a Try/Catch block to trap sending errors; this is especially useful when looping through multiple sends
            try
            {
                smtpClient.Send(mailMessage);
                lblResults.Text += "<p>Message was sent</p>";
            }
            catch (SmtpException smtpEx)
            {
                lblResults.Text = smtpEx.Message;
            }
            catch (Exception ex)
            {
                lblResults.Text = ex.Message;
            }
        }
    }
}
 
 
// ************************
// Code for a page to send
//   from in order to test 
//   MailProcessor.aspx.cs:
// ************************
 
<!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>
    <title></title>
</head>
    <body>
        <form action="MailProcessor.aspx" method="post">
            <p>
                Name:<br />
                <input id="name" name="name" type="text" value="azarc3" />
            </p>
            
            <p>
                Email:<br />
                <input id="email" name="email" type="text" value="azarc3@somewhere.com" />
            </p>
            
            <p>
                Subject:<br />
                <input id="subject" name="subject" type="text" value="This is only a test" />
            </p>
            
            <p>
                Message:<br />
                <input id="message" name="message" type="text" value="blah blah blah" /><br />
            </p>
            
            <p>
                <input id="btnSubmit" type="submit" value="Send" />
            </p>
        </form>
    </body>
</html>

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
You need to build a page or service to receive those values, just like you would normally.
You'll need to make sure you set your method in Flash sends a POST submission.

After you've done that you can use the normal Request.Form.Item("{form variable name}") to get at the value. Note: They WILL come across as strings.
0
 
KaranGuptaAuthor Commented:
But debugger is not coming on Page_Load

when submit button is clicked in flash
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Kelvin McDanielSr. Developer/ConsultantCommented:
The Flash ActiveX control lives outside of the .NET Framework (IIS and the ASP.NET Worker Process too, really), so typically you won't be able to DEBUG anything the POST operation until it hits the receiving code... You actually might be able to identify the process that is Flash but I wouldn't waste any time on that.  :)

1. As long as the page you're posting to is on a server that you have Remote Debugging rights to you'll be able to debug the "receiving" side of the POST just fine.

2. If #1 doesn't apply then I suggest that you setup a temporary page on your local workstation, run it in debug mode, and point your Flash movie at that until you're confident and comfortable with the result. Once you're good with that (and assuming the fields on your test page are the same as the "production" page will assume are coming in on the POST operation) all you'll have to do is switch the target address in the Flash movie.
0
 
KaranGuptaAuthor Commented:
can you give me some website in which it is explained with example
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Sure... which version of Flash are you using?
0
 
KaranGuptaAuthor Commented:
Flash 9.0
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Here's what's necessary on the Flash side:
http://www.actionscript.org/resources/articles/559/1/Send-Mail-with-PHP-ASP-or-Perl/Page1.html
- Notes:
  + You only need to read page 1.
  + This should work for either ActionScript 2.0 or 3.0.

Here's what you need for the ASP.NET side:
http://www.asp.net/learn/videos/video-416.aspx (video tutorial)

Example code is below. Notice that I'm suggesting you use a custom handler; you don't need a full page for this, and it gives you more control of the response back to Flash. Note, this is only a simple example... you'll need to adjust it to fit your form fields and anything else you want to add.
<%@ WebHandler Language="VB" Class="EmailHandler" %>
 
Imports System
Imports System.Web
Imports System.Net.Mail
 
Public Class EmailHandler : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        
        'Create instance of main mail message class.
        Dim mailMessage As MailMessage = New MailMessage()
 
        'Configure mail mesage
        
        'Set the From address with user input
        mailMessage.From = New MailAddress(Request.Form.Item("{the 'from' emaill address field}"))
 
        'Set additinal addresses
        mailMessage.To.Add(New MailAddress(Request.Form.Item("{the address of the intended recipient}").Trim())
 
        'same syntax for the following 
        'mailMessage.CC
        'mailMessage.Bcc
        'mailMessage.ReplyTo
 
        'Set additional options
        mailMessage.Priority = MailPriority.High
        'Text/HTML
        mailMessage.IsBodyHtml = False
 
        'Set the subjet and body text
        mailMessage.Subject = Request.Form.Item("{the 'subject' field from the form}").Trim()
        mailMessage.Body = Request.Form.Item("{the 'message or body' field from the form}").Trim()
 
        'Create an instance of the SmtpClient class for sending the email
        Dim smtpClient As SmtpClient = New SmtpClient()
 
        'begin your response back to Flash
        context.Response.ContentType = "text/plain"
 
        'Use a Try/Catch block to trap sending errors
        'Especially useful when looping through multiple sends
        Try
            smtpClient.Send(mailMessage)
            context.Response.Write({whatever you want your success message/flag to be})
 
        Catch smtpExc As SmtpException
            context.Response.Write({whatever you want the appropriate message/flag to be})
 
        Catch ex As Exception
            ' if you get here, this is bad; something else is going on and you'll need to debug it
            context.Response.Write({whatever you want the appropriate message/flag to be})
 
        End Try
 
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 
End Class

Open in new window

0
 
KaranGuptaAuthor Commented:
Hi

I want values flash

I don't want to send it to the flash
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
one simple question; are you able to submit a for FROM Flash?
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Have you done the Flash half of this yet? That's actually the hardest part.

Also, I understand that you don't want to send the form POST to Flash... but don't you want Flash to know if the submission was successful? Otherwise you'll be swallowing errors that you should want to know about.

Even if you choose not to evaluate the result of the form POST the code of the provided example will work. Just comment out or remove the context.Response.Write(); statements.
0
 
KaranGuptaAuthor Commented:
Hi azarc3

I am a .net developer and I don't know anything about flash

The work in flash is done by a designer

she said

"I will send the following variables for submission:

name
email
subject
message

When a user will click on submit on the contact us page then following variables will sent to the page by POST method. "

Now the name of the page is Contact.aspx

How can I get the value from flash to .net.

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
In that case it's just like any other Web Form submission.

You can access the values using Request.Form.Item(fieldname) in the Page_Load or Page_PreRender events. Don't forget that this *"should" not* be considered a postback because it won't be sending the required field values.
0
 
KaranGuptaAuthor Commented:
Hi

I have tried to print the value on page_load using Response.Write

but I didn't get any value

can I have any example of this type on internet
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.