Multiple Fields per File

1 posts, 0 answers
  1. sergey prudnikov
    sergey prudnikov avatar
    11 posts
    Member since:
    Jan 2005

    Posted 04 Sep 2006 Link to this post


    r.a.d.controls version

    r.a.d.upload v.2.0.0+
    .NET version

    Visual Studio version

    programming language C#
    browser support

    all browsers supported by r.a.d.controls

    this method alow save multiple fields per file. common principles describe below. if you need additional information i will ready to give it.
    java script code:
    /* Multiline script */ 
    var names = new Array; 
    var count; 
    function addRow(elem){ 
        if (!tableObj.processed) { 
        recursive(tableObj.rows[tableObj.rows.length-2], 'clear'
    function remRow(elem){ 
        if (tableObj.rows.length>3){ 
    function findParent(childObj,parentTag){ 
        try {while (childObj.parentNode.tagName!=parentTag) childObj = childObj.parentNode} catch(childObj){return null
        return childObj.parentNode 
    function setIndex(tableObj){ 
        for (i=1;i<tableObj.rows.length;i++){ 
            recursive(tableObj.rows[i], 'set', i) 
    function recursive(parentObj, mode, row){ 
        var i, childObj, mode; 
        for (i=0; i<childObj.length; i++){ 
            if (childObj[i].tagName=='INPUT' || childObj[i].tagName=='SELECT' || childObj[i].tagName=='TEXTAREA'
                switch (mode){ 
                    case "save"
                    case "set"
                    case "clear"
                        if (childObj[i].tagName=='INPUT' && childObj[i].type=='file'){ 
                        else childObj[i].value='' 
            if (childObj[i].childNodes.length>0) recursive(childObj[i], mode, row) 

    server side code (c#):
    private void btnSave_Click(object sender, System.EventArgs e)  
        RadUploadContext uploadContext = RadUploadContext.Current;  
        UploadedFileCollection uploadedFiles = uploadContext.UploadedFiles;  
        if (uploadedFiles.Count > 0)  
            int currentFileID = -1;  
            for (int i = 1; i < uploadedFiles.Count + 1; i++)  
                string key = "";  
                    key = String.Format("txtPhoto{0}", currentFileID == 0 ? String.Empty : currentFileID.ToString());  
                while (currentFileID < 1000 && uploadedFiles[key] == null);  
                UploadedFile file = uploadedFiles[key];  
                if ((file.FileName.Length > 0) && (file.ContentLength > 0))  
                    string suffix = key.Substring("txtPhoto".Length);  
                    string description = Request.Form[String.Concat("txtDescription", suffix)].Trim();  
                    using (BinaryReader reader = new BinaryReader(file.InputStream))  
                        byte[] picture = reader.ReadBytes(file.ContentLength);  
                        if (picture != null)  
                            // some action, for example save to data base  
                            //DataBaseFactory.ExecuteNonQuery("AddPhotoGallery", description, picture);  

    aspx code fragment:
    <table id="formBlockInput" cellspacing="10" cellpadding="0" width="717" border="0">  
        <tr class="formHead">  
            <td width="263">  
                * Choose Image for Uploading:</td> 
            <td width="399">  
                Short Description:</td> 
            <td width="15">  
                <input class="text" id="txtPhoto" type="file" size="35" name="txtPhoto"></td> 
                <input class="text" id="txtDescription" type="text" maxlength="80" name="txtDescription"></td> 
                <onclick="remRow(this); return false" href="#">  
                    <img src="img/icon-remove.gif" border="0"></a></td>  
            <td colspan="2">  
                <hr noshade size="1">  
            <td align="right">  
                <onclick="addRow(this); return false" href="#">  
                    <img src="img/icon-add.gif" border="0"></a></td>  
    <asp:LinkButton runat="server" id="btnSave" CausesValidation="False" Text="Save" /> 
    <radu:RadProgressArea id="RadProgressArea1" runat="server" DisplayCancelButton="True"></radu:RadProgressArea> 
    <radu:RadProgressManager id="RadProgressManager1" runat="server" OnClientProgressStarted="RadProgressManagerOnClientProgressStarted" RegisterForSubmit="False"></radu:RadProgressManager> 
Back to Top