how to upload multiple file?

Rasiuddin Khan asked on October 25, 2014 21:55

I have one Form which created as ascx control.Data was saving in biz form successfully. my problem is how to upload file? i dont know which control i'm using right or not for upload file? and how to add file upload submit here rec.SetValue("UploadCV", duUploadCV.InnerAttachmentGUID); you can see below click button code.i have both code ascx and .cs in below.

my ascx design code is below.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="GraduateProgramApplication.ascx.cs" Inherits="CMSWebParts_ePortalWebPart_ePortalControl_GraduateProgramApplication" %> <%@ Register Src="~/CMSWebParts/Membership/Registration/RegistrationForm.ascx" TagName="SecurityCode" TagPrefix="cms" %> <%@ Register Src="~/CMSModules/Content/Controls/Attachments/DocumentAttachments/DirectUploader.ascx" TagName="DirectUploader" TagPrefix="cms" %> <%--<%@ Register Src="~/CMSWebParts/bizforms/bizform.ascx" TagName="BizFormWebPart" TagPrefix="uc1" %>--%>

code .cs is

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.Base; using CMS.DataEngine; using CMS.DocumentEngine; using CMS.EmailEngine; using CMS.EventLog; using CMS.FormControls; using CMS.FormEngine; using CMS.Helpers; using CMS.Localization; using CMS.MacroEngine; using CMS.Membership; using CMS.PortalControls; using CMS.PortalEngine; using CMS.Protection; using CMS.SiteProvider; using CMS.WebAnalytics; using System.Data; using CMS.GlobalHelper; using CMS.TreeEngine; using CMS.CMSHelper; using CMS.SiteProvider; using CMS.EmailEngine; using CMS.EventLog; using CMS.DataEngine; using CMS.WebAnalytics; using CMS.LicenseProvider; using CMS.PortalEngine; using CMS.SettingsProvider; using CMS.IDataConnectionLibrary;

using CMS.OnlineForms; using CMS.DataEngine; using CMS.SiteProvider; using CMS.Helpers;

using CMS.FormEngine; using CMS.SettingsProvider; using CMS.DataEngine; using CMS.GlobalHelper;

using CMS.ExtendedControls; using CMS.Helpers; using CMS.UIControls; using System.Text; using System.Web.UI.WebControls; public partial class CMSWebParts_ePortalWebPart_ePortalControl_GraduateProgramApplication : CMSAbstractWebPart { //public static int SaveSignupForm(SignupFormModel model)

protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
        GetGender();
        GetUniversity();
        GetStudyArea();
        GetSpecializationEng();

    }

}

#region "Layout properties"
public override string SkinID
{
    get
    {
        return base.SkinID;
    }
    set
    {
        base.SkinID = value;
        SetSkinID(value);
    }
}
public string NameText
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("NameText"), ResHelper.LocalizeString("{$GPAName$}"));


    }
    set
    {
        SetValue("NameText", value);
        lblName.Text = value;

    }
}

#endregion
public string DOBText
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("DOBText"), ResHelper.LocalizeString("{$GPADateOfBirth$}"));

    }
    set
    {
        this.SetValue("LastNameText", value);
        lblDOB.Text = value;
    }
}
public string EmailText
{
    get
    {
        return DataHelper.GetNotEmpty(this.GetValue("EmailText"), ResHelper.LocalizeString("{$Webparts_Membership_RegistrationForm.Email$}"));
    }
    set
    {
        this.SetValue("EmailText", value);
        lblEmail.Text = value;
    }
}
public string Submit
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("Submit"), ResHelper.LocalizeString("{$custom.custom.Submit$}"));

    }
    set
    {
        this.SetValue("Submit", value);
        btnOk.Text = value;
    }
}
public string Gender
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("Gender"), ResHelper.LocalizeString("{$GPAGender$}"));

    }
    set
    {
        this.SetValue("Gender", value);
        lblGender.Text = value;
    }
}
public string Email
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("Email"), ResHelper.LocalizeString("{$GPAEmail$}"));

    }
    set
    {
        this.SetValue("Email", value);
        lblEmail.Text = value;
    }
}
public string GSMNumber
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("GSMNumber"), ResHelper.LocalizeString("{$GPAGSMNumber$}"));

    }
    set
    {
        this.SetValue("GSMNumber", value);
        lblGSMNumber.Text = value;
    }
}
public string Grade
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("Grade"), ResHelper.LocalizeString("{$GPAGrade$}"));

    }
    set
    {
        this.SetValue("Grade", value);
        lblGrade.Text = value;
    }
}
public string ExpectGraduateDate
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("ExpectGraduateDate"), ResHelper.LocalizeString("{$GPAExpectGraduateDate$}"));

    }
    set
    {
        this.SetValue("ExpectGraduateDate", value);
        lblExpectGraduateDate.Text = value;
    }
}
public string University
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("University"), ResHelper.LocalizeString("{$GPAUniversity$}"));

    }
    set
    {
        this.SetValue("University", value);
        lblUniversity.Text = value;
    }
}
public string StudyArea
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("StudyArea"), ResHelper.LocalizeString("{$GPAStudyArea$}"));

    }
    set
    {
        this.SetValue("StudyArea", value);
        lblStudyArea.Text = value;
    }
}
public string Specialization
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("Specialization"), ResHelper.LocalizeString("{$GPASpecialization$}"));

    }
    set
    {
        this.SetValue("Specialization", value);
        lblSpecialization.Text = value;
    }
}
public string WhyJoinPAEW
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("WhyJoinPAEW"), ResHelper.LocalizeString("{$GPAWhyJoinPAEW$}"));

    }
    set
    {
        this.SetValue("WhyJoinPAEW", value);
        lblWhyJoinPAEW.Text = value;
    }
}
public string UploadCV
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("UploadCV"), ResHelper.LocalizeString("{$GPAUploadCV$}"));

    }
    set
    {
        this.SetValue("UploadCV", value);
        lblUploadCV.Text = value;
    }
}
public string Certificates
{
    get
    {
        return DataHelper.GetNotEmpty(GetValue("Certificates"), ResHelper.LocalizeString("{$GPACertificates$}"));

    }
    set
    {
        this.SetValue("Certificates", value);
        lblCertificates.Text = value;
    }
}

protected void SetupControl()
{
    if (this.StopProcessing)
    {
        // Do not process
        rfvName.Enabled = false;
        rfvDOB.Enabled = false;
        rfvEmail.Enabled = false;
        revEmail.Enabled = false;
        rfvGSMNumber.Enabled = false;
        revMobile.Enabled = false;
        rvGrade.Enabled = false;
        rfvGrade.Enabled = false;
        rvExpectGraduateDate.Enabled = false;
        rfvExpectGraduateDate.Enabled = false;
        rfvUniversity.Enabled = false;
        rfvWhyJoinPAEW.Enabled = false;
       // rfvUploadCV.Enabled = false;
       // rfvCertificates.Enabled = false;
    }
    else
    {
        // Set texts
        lblName.Text = this.NameText;
        lblDOB.Text = this.DOBText;
        btnOk.Text = this.Submit;
        lblGender.Text = this.Gender;
        lblEmail.Text = this.Email;
        lblGSMNumber.Text = this.GSMNumber;
        lblGrade.Text = this.Grade;
        lblExpectGraduateDate.Text = this.ExpectGraduateDate;
        lblUniversity.Text = this.University;
        lblStudyArea.Text = this.StudyArea;
        lblSpecialization.Text = this.Specialization;
        lblWhyJoinPAEW.Text = this.WhyJoinPAEW;
        lblUploadCV.Text = this.UploadCV;
        lblCertificates.Text = this.Certificates;
        //lddSpecialization.Items.Insert(0, new ListItem(ResHelper.GetString(ResHelper.LocalizeString("{$GPASpecialization$}"),CultureHelper.GetPreferredCulture())));
       // BizForm1.OnAfterSave += new BizForm.OnAfterSaveEventHandler(GetGender());
       // ObjectEvents.Insert.After += new EventHandler<ObjectEventArgs>(Insert_After);


        // Set required field validators texts
        rfvName.ErrorMessage = ResHelper.GetString("GPArfv");
        rfvDOB.ErrorMessage = ResHelper.GetString("GPArfv");
        rfvEmail.ErrorMessage = ResHelper.GetString("GPArfv");
        revEmail.ErrorMessage = ResHelper.GetString("GPArfv");
        rfvGSMNumber.ErrorMessage = ResHelper.GetString("GPArfv");
        revMobile.ErrorMessage = ResHelper.GetString("GPArevMobile");
        rvGrade.ErrorMessage = ResHelper.GetString("GPAGradeLess");
        rfvGrade.ErrorMessage = ResHelper.GetString("GPArfv");
        rvExpectGraduateDate.ErrorMessage = ResHelper.GetString("GPArvExpectGraduateDate");
        rfvExpectGraduateDate.ErrorMessage = ResHelper.GetString("GPArfv");
        rfvUniversity.ErrorMessage = ResHelper.GetString("GPArfv");
        rfvWhyJoinPAEW.ErrorMessage = ResHelper.GetString("GPArfv");
       // rfvUploadCV.ErrorMessage = ResHelper.GetString("Webparts_Membership_RegistrationForm.rfvLastName");
      //  rfvCertificates.ErrorMessage = ResHelper.GetString("Webparts_Membership_RegistrationForm.rfvLastName");
        // Set SkinID
        if (!this.StandAlone && (this.PageCycle < PageCycleEnum.Initialized))
        {
            SetSkinID(this.SkinID);
        }


    }
}

void SetSkinID(string skinId)
{
    if (skinId != "")
    {
        lblName.SkinID = skinId;
        lblDOB.SkinID = skinId;

    }
}

public override void OnContentLoaded()
{
    base.OnContentLoaded();
    SetupControl();

}


/// <summary>
/// Reloads data
/// </summary>
public override void ReloadData()
{
    base.ReloadData();
    SetupControl();
}

     /////////////////// Append Gender Radio List ///////////////////
private void GetGender()
{
        Dictionary<string, string> Genderdic = new Dictionary<string, string>();
        Genderdic.Add("1", "Male"); Genderdic.Add("2", "Female");
        rvGender.DataSource = Genderdic;
        rvGender.DataValueField = "Key";
        rvGender.DataTextField = "Value";
        rvGender.DataBind();
        rvGender.SelectedValue = "1";
  }
       /////////////////// Append Gender Radio List ///////////////////
        private void GetUniversity()
        {
        Dictionary<string, string> Universitydic = new Dictionary<string, string>();
        Universitydic.Add("1", "Sultan Qaboos University"); Universitydic.Add("2", "Higher College of Technology"); Universitydic.Add("3", "Other");
        ddlUniversity.DataSource = Universitydic;
        ddlUniversity.DataValueField = "Key";
        ddlUniversity.DataTextField = "Value";
        ddlUniversity.DataBind();
        }

        private void GetStudyArea()
        {
            Dictionary<string, string> StudyAreadic = new Dictionary<string, string>();
            StudyAreadic.Add("1", "Engineering"); StudyAreadic.Add("2", "Business");
            rblStudyArea.DataSource = StudyAreadic;
            rblStudyArea.DataValueField = "Key";
            rblStudyArea.DataTextField = "Value";
            rblStudyArea.DataBind();
            rblStudyArea.SelectedValue = "1";
        }
        private void GetSpecializationEng()
        {
            Dictionary<string, string> Specializationdic = new Dictionary<string, string>();
            if (rblStudyArea.SelectedValue == "1")
            {
            Specializationdic.Add("1", "Mechanical"); Specializationdic.Add("2", "Instrumentation"); Specializationdic.Add("3", "Civil"); Specializationdic.Add("4", "Chemistry"); Specializationdic.Add("5", "Water Resources"); Specializationdic.Add("6", "Other");
            }
            else
            { 
                Specializationdic.Add("1", "Finance"); Specializationdic.Add("2", "HR"); Specializationdic.Add("3", "Communication"); Specializationdic.Add("4", "BA"); Specializationdic.Add("5", "Other");
            }
            lddSpecialization.DataSource = Specializationdic;
            lddSpecialization.DataValueField = "Key";
            lddSpecialization.DataTextField = "Value";
            lddSpecialization.DataBind();
            lddSpecialization.SelectedValue = "1";
        }
        protected void ddlUniversity_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlUniversity.SelectedValue == "3")
            { txtUniversity.Visible = true;}
            else
            { txtUniversity.Visible = false;}

        }
        protected void rblStudyArea_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetSpecializationEng();
        }
        protected void lddSpecialization_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (rblStudyArea.SelectedValue == "1")
            {
                if (lddSpecialization.SelectedValue == "6")
                { txtSpecialization.Visible = true; }
                else
                { txtSpecialization.Visible = false; }
            }
            else
            {
                if (lddSpecialization.SelectedValue == "5")
                { txtSpecialization.Visible = true; }
                else
                { txtSpecialization.Visible = false; }

            }
        }
       protected void btnOk_Click(object sender, EventArgs e)
        {

                if ((this.PageManager.ViewMode == ViewModeEnum.Design) || (this.HideOnCurrentPage) || (!this.IsVisible))
                {
                    // Do not process
                }
                else
                {
                    rfvName.Validate();
                    rfvDOB.Validate();
                    rfvEmail.Validate();
                    revEmail.Validate();
                    rfvGSMNumber.Validate();
                    revMobile.Validate();
                    rvGrade.Validate();
                    rfvGrade.Validate();
                    rvExpectGraduateDate.Validate();
                    rfvExpectGraduateDate.Validate();
                    rfvUniversity.Validate();
                    rfvWhyJoinPAEW.Validate();
                    Page.Validate();
                    //if (Page.IsValid)
                    //{
                    String siteName = SiteContext.CurrentSiteName;


                    #region "Banned IPs"

                    // Ban IP addresses which are blocked for registration
                    if (!BannedIPInfoProvider.IsAllowed(siteName, BanControlEnum.Registration))
                    {
                        lblError.Visible = true;
                        lblError.Text = GetString("banip.ipisbannedregistration");
                        return;
                    }

                    #endregion

                    BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("GraduateProgramApplication", SiteContext.CurrentSiteID);
                    if (formObject != null)
                    {
                        DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
                        if (formClass != null)
                        {
                            BizFormItemProvider bProvider = new BizFormItemProvider();
                            BizFormItem rec = BizFormItem.New(formClass.ClassName, null);
                            DateTime Applicant_DOB = DateTime.ParseExact(txtDOB.Text.Trim(), "dd/MM/yyyy", null);
                            DateTime Applicant_ExpectGraduateDate = DateTime.ParseExact(txtExpectGraduateDate.Text.Trim(), "MM/dd/yyyy", null);
                            rec.SetValue("FullName", txtName.Text.Trim());
                            rec.SetValue("DOB", Applicant_DOB);
                            rec.SetValue("Gender", rvGender.SelectedItem.Text.Trim());
                            rec.SetValue("Email", txtEmail.Text.Trim());
                            rec.SetValue("GSMNumber", txtGSMNumber.Text.Trim());
                            rec.SetValue("Grade", txtGrade.Text.Trim());
                            rec.SetValue("ExpectGraduateDate", Applicant_ExpectGraduateDate);
                            rec.SetValue("University", ddlUniversity.SelectedItem.Text.Trim());
                            rec.SetValue("StudyArea", rblStudyArea.SelectedItem.Text.Trim());
                            rec.SetValue("Specialization", lddSpecialization.SelectedItem.Text.Trim());
                            rec.SetValue("WhyPAEW", txtWhyJoinPAEW.Text.Trim());
                            // rec.SetValue("UploadCV", duUploadCV.InnerAttachmentGUID);

                            // BasicForm.Data.GetValue("answerText"), "");
                            rec.SetValue("FormInserted", DateTime.Now);
                            rec.SetValue("FormUpdated", DateTime.Now);
                            rec.Insert();
                            BizFormInfoProvider.RefreshDataCount(formObject.FormName, formObject.FormSiteID);

                        }

                    }
                    string test = "Hello";
                    Response.Write("<script>alert('" + test + "');</script>");
                }

        }

}

   Please, sign in to be able to submit a new answer.