Multiple Fields per File

Thread is closed for posting
1 posts, 0 answers
  1. BD49BEAD-8B78-4AF3-BFDA-EF8FC573A5BF
    BD49BEAD-8B78-4AF3-BFDA-EF8FC573A5BF avatar
    11 posts
    Member since:
    Jan 2005

    Posted 04 Sep 2006 Link to this post

    Requirements

    r.a.d.controls version

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

    1.1+
    Visual Studio version

    2003
    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){ 
        tableObj=findParent(elem,'TABLE'
        if (!tableObj.processed) { 
            recursive(tableObj,'save'
            tableObj.processed=true 
        } 
        tableObj.tBodies[0].insertBefore(tableObj.rows[1].cloneNode(true),tableObj.rows[tableObj.rows.length-1]) 
        recursive(tableObj.rows[tableObj.rows.length-2], 'clear'
        setIndex(tableObj) 
     
    function remRow(elem){ 
        tableObj=findParent(elem,'TABLE'
        if (tableObj.rows.length>3){ 
            trObj=findParent(elem,'TR'
            tableObj.deleteRow(trObj.sectionRowIndex) 
        } 
     
    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++){ 
            count=0 
            recursive(tableObj.rows[i], 'set', i) 
        } 
     
    function recursive(parentObj, mode, row){ 
        var i, childObj, mode; 
        childObj=parentObj.childNodes 
        for (i=0; i<childObj.length; i++){ 
            if (childObj[i].tagName=='INPUT' || childObj[i].tagName=='SELECT' || childObj[i].tagName=='TEXTAREA'
                switch (mode){ 
                    case "save"
                        names[tableObj,names.length]=childObj[i].name 
                    break 
                    case "set"
                        childObj[i].id=childObj[i].name=names[tableObj,count]+row.toString() 
                        count++ 
                    break 
                    case "clear"
                        if (childObj[i].tagName=='INPUT' && childObj[i].type=='file'){ 
                            // 
                        } 
                        else childObj[i].value='' 
                    break 
                } 
            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 = "";  
     
                do 
                {  
                    currentFileID++;  
     
                    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">  
                &nbsp;</td> 
        </tr> 
        <tr> 
            <td> 
                <input class="text" id="txtPhoto" type="file" size="35" name="txtPhoto"></td> 
            <td> 
                <input class="text" id="txtDescription" type="text" maxlength="80" name="txtDescription"></td> 
            <td> 
                <onclick="remRow(this); return false" href="#">  
                    <img src="img/icon-remove.gif" border="0"></a></td>  
        </tr> 
        <tr> 
            <td colspan="2">  
                <hr noshade size="1">  
            </td> 
            <td align="right">  
                <onclick="addRow(this); return false" href="#">  
                    <img src="img/icon-add.gif" border="0"></a></td>  
        </tr> 
    </table> 
    <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

This Code Library is part of the product documentation and subject to the respective product license agreement.