Uploading a file form .aspx to SQL 05 failed

Uploading a file from an .aspx file to SQL 05 database not working.

Page 1 of 1

10 Replies - 1917 Views - Last Post: 11 February 2010 - 09:34 AM Rate Topic: -----

#1 nonpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-February 10

Uploading a file form .aspx to SQL 05 failed

Posted 09 February 2010 - 01:45 PM

I had a form working correctly and entering data into a SQL 2005 server, but when I add the upload code, it ignores the selected file, but submits all other information to the database without giving me any errors.
Thie following is part of the .aspx file:

 <asp:FileUpload ID="fAttached_Other" enctype="multipart/form-data" runat="server" /> 
<asp:Button Width="200" CssClass="stdButton" runat="server" ID="btnSubmit" UseSubmitbehavior="true" Text="Submit File" /> 


The following is part of the .cs file:

protected void Page_Load(object sender, EventArgs e) 
{ 
    frmPreApp.Focus(); 
 
    btnSubmit.Click += new EventHandler(btnSubmit_Click); 
    if (!IsPostBack) 
    { 
        AddStandardCaptchaColors(); 
        comboColors.DataSource = ColorCaptcha1.GetPossibleColors(); 
    } 
 
    DataBind(); 
}


This is what I need to call when the .aspx file is uploaded to the SQL database.

public void Save() 
{ 
    if (fAttached_Other.HasFile) 
    { 
        fAttached_Other.SaveAs(@"C:\DB\web\HR\Original_PreApp\PreApp\Uploaded_Files\" + fAttached_Other.FileName); 
    } 
} 


This post has been edited by nonpro: 09 February 2010 - 03:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Uploading a file form .aspx to SQL 05 failed

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Uploading a file form .aspx to SQL 05 failed

Posted 09 February 2010 - 02:05 PM

Where is the code for the btnSubmit_Click event?

And the code that saves everything to the database?

So are you planning on actually storing the file in Sql Server or just the location to where the file is located on your server?
Was This Post Helpful? 0
  • +
  • -

#3 nonpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-February 10

Re: Uploading a file form .aspx to SQL 05 failed

Posted 09 February 2010 - 03:26 PM

View PostJayman, on 09 February 2010 - 01:05 PM, said:

Where is the code for the btnSubmit_Click event?

And the code that saves everything to the database?

So are you planning on actually storing the file in Sql Server or just the location to where the file is located on your server?


btnSubmit code:
void btnSubmit_Click(object sender, EventArgs e)
    {
       SubmitApplication(bool.Parse(hiddenSuccess.Value));
    }


I would like the file to go to a folder in the same subweb called "Uploaded_Files"

The database field I'm using is
<Column Name="Attached_Other" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />


I'm trying to modify a project that someone else had originally created.
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Uploading a file form .aspx to SQL 05 failed

Posted 09 February 2010 - 05:17 PM

Where is the code for the SubmitApplication method?

And you still need to post the code that saves the data to the database. It is very difficult to answer your question without seeing what you are doing.
Was This Post Helpful? 0
  • +
  • -

#5 nonpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-February 10

Re: Uploading a file form .aspx to SQL 05 failed

Posted 09 February 2010 - 06:36 PM

View PostJayman, on 09 February 2010 - 04:17 PM, said:

Where is the code for the SubmitApplication method?

And you still need to post the code that saves the data to the database. It is very difficult to answer your question without seeing what you are doing.


Sorry. I'm kind of new to this group and not sure if I'm posting too much information.

 // Submits the application to the SQL Server database.
 public virtual int SubmitToDatabase()
    {
        PreApplicationsDataContext db =
            new PreApplicationsDataContext(
                "Data Source=thewebserver;Initial Catalog=dataconnection;Integrated Security=True");
        tblPreApplication preApp = new tblPreApplication();
        preApp.FirstGuardian = FirstGuardian;
        preApp.Address = Address;
        preApp.City = City;
        //Several more fiels here
        preApp.Attached_Other = Attached_Other;

        try
       
        {
            db.tblPreApplications.Insertonsubmit(preApp);
            db.SubmitChanges();
            DatabaseId = preApp.Applicant_PK;
            return preApp.Applicant_PK;
        }
        catch
        {
            DatabaseId = 0;
            return 0;   
        }        
    }


And this code attempts to submit the application.
 /// Attempts to submit the application.
      void SubmitApplication(bool success)
        {
        if (!success && ValidateDataEntry())
        {                      
            ScriptManager.RegisterStartupScript(this.Page, typeof(object), "HideForm", "submitSuccess(true);", true);
            successDisplay.Visible = true;
            lblReference.Text = Resources.PreAppLanguage.txtSubmitting;

        }
    
        if(success)
        {
            ScriptManager.RegisterStartupScript(this.Page, typeof(object), "HideForm", "submitSuccess(false);", true);
            CreatePreApplication();            
            int returnVal = Pre_Application.SubmitToDatabase();
            Pre_Application.SendApplicationByEmail();
            lblReference.Text = Resources.PreAppLanguage.txtSubmitted + " " + returnVal + ". <br/> ";
        }
   }

This post has been edited by nonpro: 10 February 2010 - 08:30 AM

Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Uploading a file form .aspx to SQL 05 failed

Posted 10 February 2010 - 08:27 AM

You can never provide to much information.

However, we still need to dig deeper to get to the actual code that saves to the database. Whether it is Stored Procedure or a Sql statement, this is what I need to see. If it is a stored procedure, then include that with the code.

You say the uploaded file location is not being saved to the database and this is a new addition. So post the code for the following two methods where the data is actually saved to the database.

I am guessing the code I'm looking for is in the Insertonsubmit method.

db.tblPreApplications.Insertonsubmit(preApp);
db.SubmitChanges();


Thanks.
Was This Post Helpful? 0
  • +
  • -

#7 nonpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-February 10

Re: Uploading a file form .aspx to SQL 05 failed

Posted 10 February 2010 - 09:02 AM

View PostJayman, on 10 February 2010 - 07:27 AM, said:

You can never provide to much information.

However, we still need to dig deeper to get to the actual code that saves to the database. Whether it is Stored Procedure or a Sql statement, this is what I need to see. If it is a stored procedure, then include that with the code.

You say the uploaded file location is not being saved to the database and this is a new addition. So post the code for the following two methods where the data is actually saved to the database.

I am guessing the code I'm looking for is in the Insertonsubmit method.

db.tblPreApplications.Insertonsubmit(preApp);
db.SubmitChanges();


Thanks.


This is the file that has the Insertonsubmit, located App_Code direcotry;

using System;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Net.Mail;
using System.Net;
using System.Text;

/// <summary>
/// Class representation of application
/// </summary>
public class PreApplication
{
    public int DatabaseId { get; set; }
    public String FirstGuardian { get; set; }
    public String Address { get; set; }
    public String City { get; set; }
    public String State { get; set; }
    public String County { get; set; }
    public String Zipcode { get; set; }
    public String Phone { get; set; }
    public String AlternatePhone { get; set; }
    public String Email{get;set;}
    public IEnumerable<Child> Children { get; set; }
    public Boolean CompletedInSpanish { get; set; }
    public DateTime DateSubmitted { get; set; }
    public String Resume_Text { get; set; }
    public String Head_Start_Parent { get; set; }
    public int JP_FK { get; set; }
    public String Current_Status { get; set; }
    public Boolean HeadStartParentYes { get; set; }
    public String Learn_About { get; set; }
    public String Highest_Ed { get; set; }
    public String Major { get; set; }
    public String Attached_Other { get; set; }
    public PreApplication()
  
	{        
    }

    /// <summary>
    /// Send application by e-mail. Can be overriden to provide alternate functionality. 
    /// </summary>
    public virtual void SendApplicationByEmail()
    {        
        BackgroundWorker bw = new BackgroundWorker();
        bw.DoWork += SendApplicationByEmailAsync;
        bw.RunWorkerAsync();        
    }

    /// <summary>
    /// Send an e-mail with the current application asyncronously, used by the default implmentation of SendApplicationByEmail(). Can be overriden. 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected virtual void SendApplicationByEmailAsync(object sender, DoWorkEventArgs e)
    {
        MailMessage msg = new MailMessage();
        //msg.From = new MailAddress("sample@somewhere.net,"Automated Application Email");
        //msg.To.Add(new MailAddress("sample@somewhere.net"));
        //msg.Bcc.Add(new MailAddress("sample@somewhere.net"));
        try
        {
            MailAddress tempAddress = new MailAddress(Email, FirstGuardian);
            msg.To.Add(tempAddress);
        }
        catch {}
        msg.Subject = "Application Submitted.";
        msg.IsBodyHtml = true;
        msg.Body = GetPreApplicationString();

        SmtpClient mailClient = new SmtpClient();
        mailClient.Host = "mail.somewhere.net";        
        mailClient.SendAsync(msg, "BA");
    }

    /// <summary>
    /// OBSOLETE.
    /// </summary>
    /// <param name="text"></param>
    /// <param name="values"></param>
    /// <returns></returns>
    public static string QuickHTMLFormat(string text, params object[] values)
    {
        return String.Format(text, values) + "<br/>";
    }

    /// <summary>
    /// Submits the application to the SQL Server database. Can be overriden. 
    /// </summary>
    /// <returns>The new primary key integer of the inserted record. </returns>
    public virtual int SubmitToDatabase()
    {
        PreApplicationsDataContext db =
            new PreApplicationsDataContext(
                "Data Source=thewebserver;Initial Catalog=dataconnection;Integrated Security=True");
        tblPreApplication preApp = new tblPreApplication();
        preApp.FirstGuardian = FirstGuardian;
        preApp.Address = Address;
        preApp.City = City;
        preApp.CompletedInSpanish = CompletedInSpanish;
        preApp.DateSubmitted = DateSubmitted;
        preApp.Email = Email;
        preApp.Phone = Phone;
        preApp.AlternatePhone = AlternatePhone;
        preApp.State = State;
        preApp.Zipcode = Zipcode;
        preApp.Resume_Text = Resume_Text;
        preApp.JP_FK = JP_FK;
        preApp.Current_Status = Current_Status;
        preApp.HeadStartParentYes = HeadStartParentYes;
        preApp.Learn_About = Learn_About;
        preApp.Highest_Ed = Highest_Ed;
        preApp.Major = Major;
        preApp.Attached_Other = Attached_Other;

        try
       
        {
            db.tblPreApplications.Insertonsubmit(preApp);
            db.SubmitChanges();
            DatabaseId = preApp.Applicant_PK;
            return preApp.Applicant_PK;
        }
        catch
        {
            DatabaseId = 0;
            return 0;   
        }        
    }

    /// <summary>
    /// Overriden to call GetPreApplicationString().
    /// </summary>
    /// <returns><see cref="GetPreApplicationString()"/></returns>
    public override string ToString()
    {
        return GetPreApplicationString();
    }

    /// <summary>
    /// Returns a string representation of the PreApplication class. Used primarily to support the SendApplicationByEmail() method.
    /// </summary>
    /// <returns>String representation of current PreApplication instance.</returns>
    public string GetPreApplicationString()
    {                
        StringBuilder sb = new StringBuilder();        
        sb.AppendLine("<body style=\"background-color:White;font-family:Verdana;font-size:12px\">");
        sb.AppendLine(String.Format("<h2>Application # {0}</h2><br/>", DatabaseId));
        sb.AppendLine(String.Format("<b>Applying for Job #:</b> {0}", JP_FK.ToString()));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>First Name:</b> {0}", FirstGuardian));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Address:</b> {0}", Address));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>City:</b> {0}", City));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>State:</b> {0}", State));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Zipcode:</b> {0}", Zipcode));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Phone:</b> {0}", Phone));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>AlternatePhone:</b> {0}", AlternatePhone));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Email:</b> {0}", Email));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Head Start Parent:</b> {0}", Head_Start_Parent));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>CompletedInSpanish:</b> {0}", CompletedInSpanish.ToString()));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Date Submitted:</b> {0}", DateSubmitted.ToString()));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Learn about: </b> {0}", Learn_About));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Highest Ed: </b> {0}", Highest_Ed));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Major: </b> {0}", Major));
        sb.AppendLine("<br/>");
        sb.AppendLine(String.Format("<b>Text Resume:</b> {0}", Resume_Text.ToString()));
        sb.AppendLine("<br/>");
        sb.AppendLine("</body>");
        return sb.ToString();
    }    
}



This is the actual .aspx form I'm usging:
<%@ Page Language="C#" AutoEventWireup="true" Async="true" AsyncTimeout="0" CodeFile="default.aspx.cs"
    Inherits="PreApp" EnableViewState="true" %>

<%@ Import Namespace="Resources" %>
<%@ Register Assembly="ColorCaptcha" Namespace="ColorCaptcha" TagPrefix="cc1" %>
<!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>Job Application</title>
    
                             
    <script src="includes/ufunc.js" type="text/javascript"></script>

    <script src="includes/newsiteufunc.js" type="text/javascript"></script>
    
    <link href="includes/CenterDiv.css" rel="stylesheet" type="text/css" />
    <link href="includes/PreApp.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">        
      function submitSuccess(submitForm) {
        var d = document.getElementById("formDisplay");
        d.style.display = "none";                
        var s = document.getElementById("hiddenSuccess");
        s.value = "true";
        if(submitForm)
        {
            var b = document.getElementById("btnSubmit");        
            b.click();
        }
      }                
    </script>

</head>
<body>    
    <form defaultbutton="btnSubmit" id="frmPreApp" enctype="multipart/form-data" runat="server" enableviewstate="true">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <h1>
        &nbsp;&nbsp;<%=Resources.PreAppLanguage.txtPreAppContactUs %></h1>
    <br />
    <div runat="server" style="left: 40px; position: relative; overflow: hidden;">
        <font class="newH2">
            <%=Resources.PreAppLanguage.txtPreApp %></font>
        <asp:UpdatePanel ID="childUpdatePanel" runat="server">
            <ContentTemplate>
                <asp:HiddenField ID="hiddenSuccess" runat="server" Value="false" />
                <asp:Panel ID="successDisplay" runat="server">
                    <asp:Label Text="" runat="server" ID="lblReference" Visible="true"></asp:Label>
                </asp:Panel>
                <asp:Panel ID="formDisplay" runat="server">
                    <asp:Table ID="preAppTable" CssClass="preAppTable" BorderWidth="1" GridLines="Both" Visible="true" BorderColor="Black" Width="50%" runat="server">
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right"></asp:TableHeaderCell>
                            <asp:TableHeaderCell HorizontalAlign="Left" ColumnSpan="1">
                                <asp:Label runat="server" Width="200" ID="lblFirstName" Text="<%$ Resources:PreAppLanguage, txtChildFirstName %>" />
                                <asp:Label runat="server" ID="lblLastName" Text="<%$ Resources:PreAppLanguage, txtChildLastName %>" /></asp:TableHeaderCell>
                               <asp:TableHeaderCell></asp:TableHeaderCell> 
                               </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right"><asp:Literal runat="server" Text="<%$ Resources:PreAppLanguage, txtParent %>" /></asp:TableHeaderCell>
                            <asp:TableCell>                           
                                <asp:TextBox ID="txtGuardian1_firstName" Style="margin-right:28px;" Width="170" runat="server" />
                                                     <asp:TextBox ID="txtGuardian1_lastName" Width="170" runat="server" />
                                </asp:TableCell>
                                <asp:TableCell HorizontalAlign="Center"></asp:TableCell>
                                                          
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                </asp:TableHeaderCell>
                            <asp:TableCell>
                                     </asp:TableCell>
                                                <asp:TableCell HorizontalAlign="Center"></asp:TableCell>                                                                                     
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal2" runat="server" Text="<%$ Resources:PreAppLanguage, txtAddress %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:TextBox ID="txtAddress" Width="400" runat="server" /></asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:PreAppLanguage, txtCity %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:TextBox ID="txtCity" Width="125" runat="server" /></asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal4" runat="server" Text="<%$ Resources:PreAppLanguage, txtState %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:TextBox ID="txtState" Width="25" MaxLength="2" runat="server" /></asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                </asp:TableHeaderCell>
                            <asp:TableCell>                                
                            </asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal5" runat="server" Text="<%$ Resources:PreAppLanguage, txtZipcode %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:TextBox ID="txtZipcode" Width="100" runat="server" /></asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal6" runat="server" Text="<%$ Resources:PreAppLanguage, txtPhone %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:TextBox ID="txtPhone" Width="100" runat="server" /></asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal7" runat="server" Text="<%$ Resources:PreAppLanguage, txtAlternatePhone %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:TextBox ID="txtAltPhone" Width="100" runat="server" /></asp:TableCell>
                        </asp:TableRow>
                         <asp:TableRow>
                           <asp:TableHeaderCell HorizontalAlign="Right">
                           <asp:Label ID="Literal10" runat="server" Text="<%$ Resources:PreAppLanguage, txtHead_Start_Parent %>" /></asp:TableHeaderCell>
                           
                           <asp:TableCell><asp:Literal ID="Literal12" runat="server" Text="<%$ Resources:PreAppLanguage, txtHeadStartParentYes %>" />
                                 <br />
                              
                              <asp:RadioButton GroupName="radioHeadStartGroup" HorizontalAlign="Left" Checked="False" runat="server" ID="radioHeadStartYes" /> <asp:RadioButton GroupName="radioHeadStartGroup" runat="server" ID="radioHeadStartNo" />
                              </asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                           <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal8" runat="server" Text="<%$ Resources:PreAppLanguage, txtEmail %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:TextBox ID="txtEmail" Width="200" runat="server" /></asp:TableCell>
                        </asp:TableRow>
                        
                     <asp:TableRow>
                           <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:PreAppLanguage, txtHighest_Ed %>" />
                                </asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:DropDownList ID="ddlHighest_Ed" Width="200" runat="server">
                                <asp:ListItem Value="null">?</asp:ListItem>
                                <asp:ListItem Value="PhD">PhD</asp:ListItem>
                                <asp:ListItem Value="MBA ">MBA  </asp:ListItem>
                                <asp:ListItem Value="BA/BS">BA/BS</asp:ListItem>
                                <asp:ListItem Value="AA">AA</asp:ListItem>
                                <asp:ListItem Value="OtherRelated">Other</asp:ListItem>
                                <asp:ListItem Value="HS">High School Diploma</asp:ListItem>
                                <asp:ListItem Value="GED">GED</asp:ListItem>
                                </asp:DropDownList>
                                </asp:TableCell>
                        </asp:TableRow>
                        
                                   <asp:TableRow>
                           <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal13" runat="server" Text="Major" />
                                </asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:DropDownList ID="ddlMajor" Width="200" runat="server">
                                <asp:ListItem Value="null">?</asp:ListItem>
                                <asp:ListItem Value="Ed">Education</asp:ListItem>
                                <asp:ListItem Value="Early Childhood Ed">Early Childhood Education</asp:ListItem>
                                <asp:ListItem Value="Social Work">Social Work</asp:ListItem>
                                <asp:ListItem Value="Mental Health & Disabilities">Mental Health & Disabilities</asp:ListItem>
                                <asp:ListItem Value="Social Work">Social Work</asp:ListItem>
                                <asp:ListItem Value="Sociology">Sociology</asp:ListItem>
                                <asp:ListItem Value="MHD">Mental Health & Disabilities</asp:ListItem>
                                <asp:ListItem Value="HR">Human Resources</asp:ListItem>
                                <asp:ListItem Value="Accounting">Accounting</asp:ListItem>
                                <asp:ListItem Value="Public Admin">Public Administration</asp:ListItem>
                                <asp:ListItem Value="Business">Business</asp:ListItem>
                                <asp:ListItem Value="IT Related">IT Related</asp:ListItem>
                                </asp:DropDownList>
                                </asp:TableCell>
                        </asp:TableRow>
                        
                        <asp:TableRow>
                           <asp:TableHeaderCell HorizontalAlign="Right">
                                <asp:Literal ID="Literal9" runat="server" Text="<%$ Resources:PreAppLanguage, txtLearn_About %>" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                <asp:DropDownList ID="ddlLearn_About" Width="200" runat="server">
                                <asp:ListItem Value="null">?</asp:ListItem>
                                <asp:ListItem Value="careerbuilder"> careerbuilder.com</asp:ListItem>
                                <asp:ListItem Value="craigslist">craigslist.org </asp:ListItem>
                                <asp:ListItem Value="NewspaperAd">Newspaper Ad </asp:ListItem>
                                 <asp:ListItem Value="Radio">Radio</asp:ListItem>
                                <%--<asp:ListItem Value="EmployeeRef" Text="Employee Referral" />
                                <asp:ListItem Value="StateEmpOffice" Text="State Employment Office" />
                                <asp:ListItem Value="Radio" Text="Radio" />
                                <asp:ListItem Value="Walk-in" Text="Walk-in" />--%>
                                </asp:DropDownList>
                                </asp:TableCell>
                        </asp:TableRow>
                                              
                        
                      <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Right">
  

                                <asp:Literal ID="Literal14" runat="server" Text="Resume:" /></asp:TableHeaderCell>
                            <asp:TableCell>
                                
                                <asp:FileUpload ID="fAttached_Other" runat="server" />
                            </asp:TableCell>
                                
                        </asp:TableRow>
                        
                                              
                        
                   <asp:TableRow> <asp:TableCell><asp:Label ID="lblVerifiy" runat="server" CssClass="warningText" />
                   </asp:TableCell> </asp:TableRow>
                                             
                        <asp:TableRow>
                            <asp:TableHeaderCell HorizontalAlign="Left" Width="15%">
                            <asp:Literal ID="Literal11" runat="server" Text="<%$ Resources:PreAppLanguage, txtResume_Text %>" /></asp:TableHeaderCell>
                          <asp:TableCell>
                            <asp:TextBox ID="txtResume_Text" width="500" rows="10" columns="70" TextMode="multiline" runat="server" /></asp:TableCell>
                              </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableCell HorizontalAlign="right" ColumnSpan="35" Width="100%">
                                <cc1:ColorCaptcha ID="ColorCaptcha1" DropShadow="true" ColorCount="1" runat="server"
                                    Height="35" Width="35" Visible="true" />
                                <%=PreAppLanguage.txtVerification %>
                                <asp:DropDownList ID="comboColors" runat="server" AppendDataBoundItems="false" />

                            </asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableCell ColumnSpan="9" HorizontalAlign="Right" Width="100%">
                                <asp:Button Width="200" CssClass="stdButton" runat="server" ID="btnSubmit" UseSubmitbehavior="true"
                                    Text="<%$ Resources:PreAppLanguage, txtSubmitApplication %>" />
                            </asp:TableCell>
                        </asp:TableRow>
                      </asp:Table>
                    </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    
    </div>
    </form>
</body>
</html>


This is the aspx.cs file for the aspx from above:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using ColorCaptcha;


/// <summary>
/// Main application page.
/// </summary>

public partial class PreApp : System.Web.UI.Page
{
    /// <summary>
    /// Instance of PreApplication class.
    /// </summary>
    public PreApplication Pre_Application
    {
        get
        {
            return (PreApplication)Session["preApp"];
        }
        set
        {
            Session.Add("preApp", value);
        }
    }

    /// <summary>
    /// Virtual property that checks whether the clients langauge is English or not.
    /// </summary>
    bool IsEnglish
    {
        get
        {
            string language = Request.QueryString["lang"];
            HttpCookie cLang = Request.Cookies.Get("clientLanguage");

            return ((language == "EN") || (cLang!=null && cLang.Value == "English"));
        }
    }


    /// <summary>
    /// Loads the page.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        frmPreApp.Focus();

        btnSubmit.Click += new EventHandler(btnSubmit_Click);
  
        if (!IsPostBack)
        {
            AddStandardCaptchaColors();
            comboColors.DataSource = ColorCaptcha1.GetPossibleColors();
        }
      
        DataBind();
    }

  
    /// <summary>
    /// Calls <see cref="SubmitApplication"/> passing the value of a hidden field for its <typeparamref name="bool"/>
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param> 
    void btnSubmit_Click(object sender, EventArgs e)
    {
       SubmitApplication(bool.Parse(hiddenSuccess.Value));

    }
       
    
    /// <summary>
    /// Attempts to submit the application.
    /// </summary>
    /// <param name="success"></param> 
    void SubmitApplication(bool success)
        {
        if (!success && ValidateDataEntry())
        {                      
            ScriptManager.RegisterStartupScript(this.Page, typeof(object), "HideForm", "submitSuccess(true);", true);
            successDisplay.Visible = true;
            lblReference.Text = Resources.PreAppLanguage.txtSubmitting;

        }
    
        if(success)
        {
            ScriptManager.RegisterStartupScript(this.Page, typeof(object), "HideForm", "submitSuccess(false);", true);
            CreatePreApplication();            
            int returnVal = Pre_Application.SubmitToDatabase();
            Pre_Application.SendApplicationByEmail();
            lblReference.Text = Resources.PreAppLanguage.txtSubmitted + " " + returnVal + ". ";
        }
        
        
       
    }

    /// <summary>
    /// Adds standard captcha colors.
    /// </summary>
    void AddStandardCaptchaColors()
    {
        if (!IsEnglish)
        {
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Red, "Rojo"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Green, "Verde"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Blue, "Azul"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Yellow, "Amarillo"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Orange, "Naraja"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Pink, "Rosa"));
        }
        else
        {
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Red, "Red"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Green, "Green"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Blue, "Blue"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Yellow, "Yellow"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Orange, "Orange"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Pink, "Pink"));
        }
    }

    /// <summary>
    /// Used to support localization.
    /// </summary>
    protected override void InitializeCulture()
    {
        if(!IsEnglish)
        {
            Page.UICulture = "es-mx";
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-mx");
        }
        else
        {
            Page.UICulture = "en-us";
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
        }
    }

    /// <summary>
    /// Validates entered data.
    /// </summary>
    /// <returns>True if entered data passes validation, False if not.</returns>
    bool ValidateDataEntry()
    {
        bool valid = true;
        StringBuilder sb = new StringBuilder();

        if (String.IsNullOrEmpty(txtGuardian1_firstName.Text) )
        {
            valid = false;
            sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtGuardianFail);
        }
        //if (String.IsNullOrEmpty(txtAddress.Text) || String.IsNullOrEmpty(txtCity.Text) || String.IsNullOrEmpty(txtZipcode.Text) || String.IsNullOrEmpty(txtState.Text))
        //{
        //    valid = false;
        //    sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtAddressFail);
        //}
        if(String.IsNullOrEmpty(txtPhone.Text)&& String.IsNullOrEmpty(txtAltPhone.Text) && String.IsNullOrEmpty(txtEmail.Text))
        {
            valid = false;
            sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtPhoneFail);
        }

        //if(!ColorCaptcha1.ValidColor(comboColors.SelectedValue))
        //{
        //    valid = false;
        //    sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtVerificationFail);
        //    txtCaptcha.Text = "";                        
        //}
        
        if(sb.Length>1)
        {
            lblVerifiy.ForeColor = System.Drawing.Color.Red;
            lblVerifiy.Text = Resources.PreAppLanguage.txtValidationFail + sb.ToString();
        }

        return valid;
    }

    /// <summary>
    /// Creates a new pre application from entered data.
    /// </summary>
    void CreatePreApplication()
    {
        Pre_Application = new PreApplication();
        Pre_Application.FirstGuardian = txtGuardian1_firstName.Text + " " + txtGuardian1_lastName.Text;
        Pre_Application.FirstGuardian = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Pre_Application.FirstGuardian);
        Pre_Application.Address = txtAddress.Text;
        Pre_Application.AlternatePhone = txtAltPhone.Text;
        Pre_Application.City = txtCity.Text;
        Pre_Application.CompletedInSpanish = !IsEnglish;
        Pre_Application.DateSubmitted = DateTime.Now;
        Pre_Application.Email = txtEmail.Text;
        //Pre_Application.Head_Start_Parent = txtHead_Start_Parent.Text;
        Pre_Application.Phone = txtPhone.Text;
        Pre_Application.State = txtState.Text.ToUpper();
        Pre_Application.Zipcode = txtZipcode.Text;
        Pre_Application.Resume_Text = txtResume_Text.Text;
        Pre_Application.JP_FK = 1;
        Pre_Application.Current_Status = "Applied";
        Pre_Application.HeadStartParentYes = radioHeadStartNo.Checked ? false : true;
        Pre_Application.Learn_About = ddlLearn_About.SelectedValue;
        Pre_Application.Highest_Ed = ddlHighest_Ed.SelectedValue;
        Pre_Application.Major = ddlMajor.SelectedValue;
        Pre_Application.Attached_Other = fAttached_Other.FileName;
    }
}

Thanks for looking at this.
Was This Post Helpful? 0
  • +
  • -

#8 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Uploading a file form .aspx to SQL 05 failed

Posted 10 February 2010 - 09:23 AM

Sorry guess I should have been more explicit.

Can you post the code for the PreApplicationsDataContext class?

This is where the code is located for the insertonsubmit method.
Was This Post Helpful? 0
  • +
  • -

#9 Hwang Sung Wook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-February 10

Re: Uploading a file form .aspx to SQL 05 failed

Posted 10 February 2010 - 05:27 PM

um... i think it is duplicate problem.
a file 'aaa.txt' is upload your server and re-upload 'aaa.txt' again, the server causes error, and your code not see the contols when duplicate file is in your server.

try insert duplicate file check , and see duplicae, insert a number back of number.

ex) aaa.txt
aaa1.txt
aaa2.txt
Was This Post Helpful? 0
  • +
  • -

#10 SanjitN  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 13
  • Joined: 11-February 10

Re: Uploading a file form .aspx to SQL 05 failed

Posted 11 February 2010 - 02:52 AM

Is PreApplicationsDataContext a custom defined class?? Because there is nothing on MSDN about this class.

Please provide the whole code as Jayman suggested.
Was This Post Helpful? 0
  • +
  • -

#11 nonpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-February 10

Re: Uploading a file form .aspx to SQL 05 failed

Posted 11 February 2010 - 09:34 AM

View PostJayman, on 10 February 2010 - 08:23 AM, said:

Sorry guess I should have been more explicit.

Can you post the code for the PreApplicationsDataContext class?

This is where the code is located for the insertonsubmit method.


I apologize for not getting all the lingo yet, but hope to learn quickly. I beleive that what you are asking may be here it has the PreApplication class representation, public virtual int SubmitToDatabase() code, and db.SubmitChanges() code;.
I updated the code and was just trying to get the form to upload a file to a directory, but have not had any sucess.
public class PreApplication 
{ 
    public int DatabaseId { get; set; } 
    public String FirstGuardian { get; set; } 
    public String Address { get; set; } 
    public String City { get; set; } 
    public String State { get; set; } 
    public String County { get; set; } 
    public String Zipcode { get; set; } 
    public String Phone { get; set; } 
    public String AlternatePhone { get; set; } 
    public String Email{get;set;} 
    public IEnumerable<Child> Children { get; set; } 
    public Boolean CompletedInSpanish { get; set; } 
    public DateTime DateSubmitted { get; set; } 
    public String Resume_Text { get; set; } 
    public String Head_Start_Parent { get; set; } 
    public int JP_FK { get; set; } 
    public String Current_Status { get; set; } 
    public Boolean HeadStartParentYes { get; set; } 
    public String Learn_About { get; set; } 
    public String Highest_Ed { get; set; } 
    public String Major { get; set; } 
    public String Attached_Other { get; set; } 
    public PreApplication()  
    public String Attached_Other { get; set; }

    public FileUpload Resume_File;

    public PreApplication()

   
        {         
    } 
 
    /// <summary> 
    /// Send application by e-mail. Can be overriden to provide alternate functionality.  
    /// </summary> 
    public virtual void SendApplicationByEmail() 
    {         
        BackgroundWorker bw = new BackgroundWorker(); 
        bw.DoWork += SendApplicationByEmailAsync; 
        bw.RunWorkerAsync();         
    } 
 
    /// <summary> 
    /// Send an e-mail with the current application asyncronously, used by the default implmentation of SendApplicationByEmail(). Can be overriden.  
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    protected virtual void SendApplicationByEmailAsync(object sender, DoWorkEventArgs e) 
    { 
        MailMessage msg = new MailMessage(); 
        //msg.From = new MailAddress("sample@somewhere.net,"Automated Application Email"); 
        //msg.To.Add(new MailAddress("sample@somewhere.net")); 
        //msg.Bcc.Add(new MailAddress("sample@somewhere.net")); 
        try 
        { 
            MailAddress tempAddress = new MailAddress(Email, FirstGuardian); 
            msg.To.Add(tempAddress); 
        } 
        catch {} 
        msg.Subject = "Application Submitted."; 
        msg.IsBodyHtml = true; 
        msg.Body = GetPreApplicationString(); 
 
        SmtpClient mailClient = new SmtpClient(); 
        mailClient.Host = "mail.somewhere.net";         
        mailClient.SendAsync(msg, "BA"); 
    } 
 
    /// <summary> 
    /// OBSOLETE. 
    /// </summary> 
    /// <param name="text"></param> 
    /// <param name="values"></param> 
    /// <returns></returns> 
    public static string QuickHTMLFormat(string text, params object[] values) 
    { 
        return String.Format(text, values) + "<br/>"; 
    } 
 
    /// <summary> 
    /// Submits the application to the SQL Server database. Can be overriden.  
    /// </summary> 
    /// <returns>The new primary key integer of the inserted record. </returns> 
    public virtual int SubmitToDatabase() 
    { 
        PreApplicationsDataContext db = 
            new PreApplicationsDataContext( 
                "Data Source=thewebserver;Initial Catalog=dataconnection;Integrated Security=True"); 
        tblPreApplication preApp = new tblPreApplication(); 
        preApp.FirstGuardian = FirstGuardian; 
        preApp.Address = Address; 
        preApp.City = City; 
        preApp.CompletedInSpanish = CompletedInSpanish; 
        preApp.DateSubmitted = DateSubmitted; 
        preApp.Email = Email; 
        preApp.Phone = Phone; 
        preApp.AlternatePhone = AlternatePhone; 
        preApp.State = State; 
        preApp.Zipcode = Zipcode; 
        preApp.Resume_Text = Resume_Text; 
        preApp.JP_FK = JP_FK; 
        preApp.Current_Status = Current_Status; 
        preApp.HeadStartParentYes = HeadStartParentYes; 
        preApp.Learn_About = Learn_About; 
        preApp.Highest_Ed = Highest_Ed; 
        preApp.Major = Major; 
        preApp.Attached_Other = Attached_Other; 
 
        try 
        
        { 
            db.tblPreApplications.Insertonsubmit(preApp); 
            db.SubmitChanges(); 
            DatabaseId = preApp.Applicant_PK; 
            return preApp.Applicant_PK; 
        } 
        catch 
        { 
            DatabaseId = 0; 
            return 0;    
        }         
    } 
 
    /// <summary> 
    /// Overriden to call GetPreApplicationString(). 
    /// </summary> 
    /// <returns><see cref="GetPreApplicationString()"/></returns> 
    public override string ToString() 
    { 
        return GetPreApplicationString(); 
    } 
 
    /// <summary> 
    /// Returns a string representation of the PreApplication class. Used primarily to support the SendApplicationByEmail() method. 
    /// </summary> 
    /// <returns>String representation of current PreApplication instance.</returns> 
    public string GetPreApplicationString() 
    {                 
        StringBuilder sb = new StringBuilder();         
        sb.AppendLine("<body style=\"background-color:White;font-family:Verdana;font-size:12px\">"); 
        sb.AppendLine(String.Format("<h2>Application # {0}</h2><br/>", DatabaseId)); 
        sb.AppendLine(String.Format("<b>Applying for Job #:</b> {0}", JP_FK.ToString())); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>First Name:</b> {0}", FirstGuardian)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Address:</b> {0}", Address)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>City:</b> {0}", City)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>State:</b> {0}", State)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Zipcode:</b> {0}", Zipcode)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Phone:</b> {0}", Phone)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>AlternatePhone:</b> {0}", AlternatePhone)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Email:</b> {0}", Email)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Head Start Parent:</b> {0}", Head_Start_Parent)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>CompletedInSpanish:</b> {0}", CompletedInSpanish.ToString())); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Date Submitted:</b> {0}", DateSubmitted.ToString())); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Learn about: </b> {0}", Learn_About)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Highest Ed: </b> {0}", Highest_Ed)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Major: </b> {0}", Major)); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine(String.Format("<b>Text Resume:</b> {0}", Resume_Text.ToString())); 
        sb.AppendLine("<br/>"); 
        sb.AppendLine("</body>"); 
        return sb.ToString(); 
    }     
}



dbml file.


<?xml version="1.0" encoding="utf-8"?>
<Database Name="dataconnection" Class="PreApplicationsDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
  <Connection Mode="WebSettings" ConnectionString="Data Source=thewebserver;Initial Catalog=dataconnection;Integrated Security=True" SettingsObjectName="System.Configuration.ConfigurationManager.ConnectionStrings" SettingsPropertyName="JobPostingsConnectionString" Provider="System.Data.SqlClient" />
    <Table Name="dbo.Applicants" Member="tblPreApplications">
    <Type Name="tblPreApplication">
      <Column Name="Applicant_PK" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
      <Column Name="FirstGuardian" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
      <Column Name="Address" Type="System.String" DbType="VarChar(100)" CanBeNull="true" />
      <Column Name="City" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
      <Column Name="State" Type="System.String" DbType="VarChar(2)" CanBeNull="true" />
      <Column Name="Zipcode" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
      <Column Name="Phone" Type="System.String" DbType="nChar(10)" CanBeNull="true" />
      <Column Name="AlternatePhone" Type="System.String" DbType="nChar(10)" CanBeNull="true" />
      <Column Name="CompletedInSpanish" Type="System.Boolean" DbType="Bit" CanBeNull="true" />
      <Column Name="DateSubmitted" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
      <Column Name="Email" Type="System.String" DbType="VarChar(MAX)" CanBeNull="true" />
      <Column Name="HeadStartParentYes" Type="System.Boolean" DbType="Bit" CanBeNull="true" />
      <Column Name="Resume_Text" Type="System.String" DbType="Text" CanBeNull="true" />
      <Column Name="IsReviewed" Type="System.Boolean" DbType="Bit NOT NULL" CanBeNull="false" />
      <Column Name="JP_FK" Type="System.int32" DbType="Bit" CanBeNull="true" />
      <Column Name="Current_Status" Type="System.String" DbType="VarChar(10)" CanBeNull="true" />
      <Column Name="Learn_About" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
      <Column Name="Highest_Ed" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
      <Column Name="Major" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />
      <Column Name="Attached_Other" Type="System.String" DbType="VarChar(50)" CanBeNull="true" />

      <Association Name="PreApplication_tblPreApplicationChild" Member="tblPreApplicationChilds" ThisKey="Applicant_PK" OtherKey="PreApplication_FK" Type="tblPreApplicationChild" />
    </Type>
  </Table>
</Database>


Updated .cs file with code that tries only to save the file to the server (but not to the database sql server):
 

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using ColorCaptcha;



/// <summary>
/// Main PreApplication page. 
/// </summary>

public partial class PreApp : System.Web.UI.Page
{
    /// <summary>
    /// Instance of PreApplication class.
    /// </summary>
    public PreApplication Pre_Application
    {
        get
        {
            return (PreApplication)Session["preApp"];
        }
        set
        {
            Session.Add("preApp", value);
        }
    }

    /// <summary>
    /// Virtual property that checks whether the clients langauge is English or not.
    /// </summary>
    bool IsEnglish
    {
        get
        {
            string language = Request.QueryString["lang"];
            HttpCookie cLang = Request.Cookies.Get("clientLanguage");

            return ((language == "EN") || (cLang!=null && cLang.Value == "English"));
        }
    }


    /// <summary>
    /// Loads the page.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        frmPreApp.Focus();

        btnSubmit.Click += new EventHandler(btnSubmit_Click);
  
        if (!IsPostBack)
        {
            AddStandardCaptchaColors();
            comboColors.DataSource = ColorCaptcha1.GetPossibleColors();
        }
      
        DataBind();
    }

  
    /// <summary>
    /// Calls <see cref="SubmitApplication"/> passing the value of a hidden field for its <typeparamref name="bool"/>
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param> 
    void btnSubmit_Click(object sender, EventArgs e)
    {
       SubmitApplication(bool.Parse(hiddenSuccess.Value));

    }
       
    
    /// <summary>
    /// Attempts to submit the application.
    /// </summary>
    /// <param name="success"></param> 
    void SubmitApplication(bool success)
        {
        if (!success && ValidateDataEntry())
        {                      
            ScriptManager.RegisterStartupScript(this.Page, typeof(object), "HideForm", "submitSuccess(true);", true);
            successDisplay.Visible = true;
            lblReference.Text = Resources.PreAppLanguage.txtSubmitting;

        }
    
        if(success)
        {
            ScriptManager.RegisterStartupScript(this.Page, typeof(object), "HideForm", "submitSuccess(false);", true);
            CreatePreApplication();            
            int returnVal = Pre_Application.SubmitToDatabase();

            if (Pre_Application.Resume_File.PostedFile != null)
            {
                // Get a reference to PostedFile object
                HttpPostedFile myFile = Pre_Application.Resume_File.PostedFile;

                //// Get size of uploaded file
                //int nFileLen = myFile.ContentLength;

                //// Allocate a buffer for reading of the file
                //byte[] myData = new byte[nFileLen];

                //// Read uploaded file from the Stream
                //myFile.InputStream.Read(myData, 0, nFileLen);
                
                string fn = System.IO.Path.GetFileName(myFile.FileName);
                string SaveLocation = Server.MapPath("Uploaded_Files") + "\\" + fn;
                try
                {
                    myFile.SaveAs(SaveLocation);
                    Response.Write("The file has been uploaded.");
                }
                catch (Exception ex)
                {
                    Response.Write("Error: " + ex.Message);
                    //Note: Exception.Message returns a detailed message that describes the current exception. 
                    //For security reasons, we do not recommend that you return Exception.Message to end users in 
                    //production environments. It would be better to put a generic error message. 
                }

            }
            else
            {
            }

            Pre_Application.SendApplicationByEmail();
            lblReference.Text = Resources.PreAppLanguage.txtSubmitted + " " + returnVal + ". <br/><br/> Main page: www.ocdc.net <br/> Jobs page: www.ocdc.net/Jobs";
        }
        
        
       
    }

    /// <summary>
    /// Adds standard captcha colors.
    /// </summary>
    void AddStandardCaptchaColors()
    {
        if (!IsEnglish)
        {
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Red, "Rojo"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Green, "Verde"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Blue, "Azul"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Yellow, "Amarillo"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Orange, "Naraja"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Pink, "Rosa"));
        }
        else
        {
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Red, "Red"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Green, "Green"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Blue, "Blue"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Yellow, "Yellow"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Orange, "Orange"));
            ColorCaptcha1.AddColor(new ColorCaptchaValidator(System.Drawing.Color.Pink, "Pink"));
        }
    }

    /// <summary>
    /// Used to support localization.
    /// </summary>
    protected override void InitializeCulture()
    {
        if(!IsEnglish)
        {
            Page.UICulture = "es-mx";
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-mx");
        }
        else
        {
            Page.UICulture = "en-us";
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
        }
    }

    /// <summary>
    /// Validates entered data.
    /// </summary>
    /// <returns>True if entered data passes validation, False if not.</returns>
    bool ValidateDataEntry()
    {
        bool valid = true;
        StringBuilder sb = new StringBuilder();

        if (String.IsNullOrEmpty(txtGuardian1_firstName.Text) )
        {
            valid = false;
            sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtGuardianFail);
        }
        //if (String.IsNullOrEmpty(txtAddress.Text) || String.IsNullOrEmpty(txtCity.Text) || String.IsNullOrEmpty(txtZipcode.Text) || String.IsNullOrEmpty(txtState.Text))
        //{
        //    valid = false;
        //    sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtAddressFail);
        //}
        if(String.IsNullOrEmpty(txtPhone.Text)&& String.IsNullOrEmpty(txtAltPhone.Text) && String.IsNullOrEmpty(txtEmail.Text))
        {
            valid = false;
            sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtPhoneFail);
        }

        //if(!ColorCaptcha1.ValidColor(comboColors.SelectedValue))
        //{
        //    valid = false;
        //    sb.AppendLine("&emsp;*" + Resources.PreAppLanguage.txtVerificationFail);
        //    txtCaptcha.Text = "";                        
        //}
        
        if(sb.Length>1)
        {
            lblVerifiy.ForeColor = System.Drawing.Color.Red;
            lblVerifiy.Text = Resources.PreAppLanguage.txtValidationFail + sb.ToString();
        }

        return valid;
    }

    /// <summary>
    /// Creates a new pre application from entered data.
    /// </summary>
    void CreatePreApplication()
    {
        Pre_Application = new PreApplication();
        Pre_Application.FirstGuardian = txtGuardian1_firstName.Text + " " + txtGuardian1_lastName.Text;
        Pre_Application.FirstGuardian = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Pre_Application.FirstGuardian);
        Pre_Application.Address = txtAddress.Text;
        Pre_Application.AlternatePhone = txtAltPhone.Text;
        Pre_Application.City = txtCity.Text;
        Pre_Application.CompletedInSpanish = !IsEnglish;
        Pre_Application.DateSubmitted = DateTime.Now;
        Pre_Application.Email = txtEmail.Text;
        Pre_Application.Phone = txtPhone.Text;
        Pre_Application.State = txtState.Text.ToUpper();
        Pre_Application.Zipcode = txtZipcode.Text;
        Pre_Application.Resume_Text = txtResume_Text.Text;
        Pre_Application.JP_FK = 1;
        Pre_Application.Current_Status = "Applied";
        Pre_Application.HeadStartParentYes = radioHeadStartNo.Checked ? false : true;
        Pre_Application.Learn_About = ddlLearn_About.SelectedValue;
        Pre_Application.Highest_Ed = ddlHighest_Ed.SelectedValue;
        Pre_Application.Major = ddlMajor.SelectedValue;
        Pre_Application.Attached_Other = fAttached_Other.FileName;

        Pre_Application.Resume_File = fAttached_Other;
    }
}


This post has been edited by nonpro: 12 February 2010 - 08:35 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1