Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need a solution that when user click multiple times on file upload control then old selected file should not remover or update latest , suppose when user select 5 file at a time and again he need 2 more file to add then it will become 7 file selected in control not 2.
my control code contain
aspx
<pre lang="HTML">
script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    function dis() {
        $(document).ready(function () {


            $(".addm").on("click", function () {

                $(".files").click();
            });
            $(".sss").on("click", function () {

                $(".files").click();
            });

            function readImage(file) {

                var reader = new FileReader();
                var image = new Image();

                reader.readAsDataURL(file);
                reader.onload = function (_file) {
                    image.src = _file.target.result;              // url.createObjectURL(file);
                    image.onload = function () {
                        var w = this.width,
                h = this.height,
                t = file.type,                           // ext only: // file.type.split('/')[1],
                n = file.name,
                s = ~ ~(file.size / 1024) + 'KB';
                        $(".f").css("visibility", "visible");
                        $('.f .g').append('<img style="max-width:102px; max-height:102px; margin-left:3px;" src="' + this.src + '"> ' + '   ');
                        $('.ms').css("display", "none");
                    };
                    image.onerror = function () {
                        alert('Invalid file type: ' + file.type);
                    };
                };

            }
            $(".files").change(function (e) {
                if (this.disabled) return alert('File upload not supported!');
                var F = this.files;
                if (F && F[0]) for (var i = 0; i < F.length; i++) readImage(F[i]);
            });
        });
    }

</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <script type="text/javascript">
            Sys.Application.add_load(dis);
        </script>
    </ContentTemplate>
</asp:UpdatePanel>
<div class="comment-box">
    <ul>
        <li><span>
            <img src="../../images/status_icon.png" alt="" /></span><asp:LinkButton ID="lnkUpdateStatus"
                runat="server" OnClick="lnkUpdateStatus_Click">Update Status</asp:LinkButton>
        </li>
        <li><span>
            <img src="../../images/add-photo-icon.png" alt="" /></span>
            <asp:LinkButton ID="lnkAddPhotoVideo" runat="server" OnClick="lnkAddPhotoVideo_Click">Add Photos/Video</asp:LinkButton>
        </li>
    </ul>
    <div class="text-area">
        <div class="corner">
        </div>
        <div class="corner-1">
        </div>
        <div class="clear">
        </div>
        <div class="text-part tt" id="Status"  runat="server">
            <asp:TextBox ID="txtstatus" CssClass="style h" runat="server" TextMode="MultiLine"></asp:TextBox>
            <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender3"  runat="server" TargetControlID="txtstatus"
                WatermarkText="Enter Your Status">
            </cc1:TextBoxWatermarkExtender>
            <div class="clear">
            </div>
            <div class="button-area">
                <asp:Button ID="btnsubmitstatus" runat="server" Text="Post" CssClass="submit-style g"
                    OnClick="btnsubmitstatus_Click" /></div>
        </div>
        <div class="text-part ms" id="AddPhotoAlbum"  runat="server" visible="false">
            <ul>
                <li>
                    <div class="sss">
                        <br />
                        <br />
                        "FileUpload1" class="multi files">Create Photo Album<br />
                    <br />
                    <br />
                    <br />
                </li>
            </ul>
            <div class="clear">
            </div>
            <div class="button-area">
                <%-- <asp:Button ID="btnPost" runat="server" Text="Post" CssClass="submit-style" />--%>
            </div>
        </div>
        <div class="text-part-1 f" id="AddPhotos" style="visibility: hidden">
            <asp:TextBox ID="txtPhoto" CssClass="style h" runat="server" TextMode="MultiLine"></asp:TextBox>
            <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1"  runat="server" TargetControlID="txtPhoto"
                WatermarkText="Enter Your Status">
            </cc1:TextBoxWatermarkExtender>
            <div class="upload-image g" id="Photo">
            </div>
            <div class="addm" style="float: left;">
           <%--     ^__b style="removed: pointer;">Add More--%>
            
            </div>
            <div class="clear">
            </div>
            <div class="button-area">
                <asp:Button ID="btnAddPhoto" runat="server" Text="Post" CssClass="submit-style" OnClick="btnAddPhoto_Click" />
            </div>
        </div>
    </div>
</div>


cs
C#
protected void btnsubmitstatus_Click(object sender, EventArgs e)
   {
       if (txtstatus.Text != "")
       {
           string User_Id = ab.GetUser_Id(uid);
           string TypeId = ab.GetTypeID("Status-Text");

           ab.InsertSlamBookStatus(txtstatus.Text, null, null, null, null, null, null, User_Id, TypeId, null, DateTime.Now.ToString(), "", "", "");
           txtstatus.Text = "";

       }
   }

   protected void lnkUpdateStatus_Click(object sender, EventArgs e)
   {
       Status.Visible = true;
       AddPhotoAlbum.Visible = false;
       //AddPhotos.Visible = false;

   }
   protected void lnkAddPhotoVideo_Click(object sender, EventArgs e)
   {
       AddPhotoAlbum.Visible = true;
       //AddPhotos.Visible = false;
       Status.Visible = false;

   }

   protected void btnAddPhoto_Click(object sender, EventArgs e)
   {
       string pt = null;
       string cpath = null;
       string PhotoFolder = "~/Photos/";
       string PhotoThumbFolder = "~/Photos/Thumb/";
       if (FileUpload1.HasFile)
       {
           string UID = ab.GetUser_Id(uid);
           string imgName = Path.GetFileName(FileUpload1.FileName);
           string date = DateTime.Now.ToString();

           while (File.Exists(Server.MapPath(PhotoFolder + imgName)))
           {
               cpath = Server.MapPath(PhotoFolder + imgName);
               pt = Server.MapPath(PhotoThumbFolder + imgName);
               File.Delete(cpath);
               File.Delete(pt);
           }

           HttpFileCollection hfc = HttpContext.Current.Request.Files;
           for (int i = 0; i < hfc.Count; i++)
           {

               HttpPostedFile hpf = hfc[i];
               if (hpf.ContentLength > 0)
               {
                   //Original Image Save
                   hpf.SaveAs(Server.MapPath(PhotoFolder) + Path.GetFileName(hpf.FileName));
                   // Load image.
                   System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(PhotoFolder) + hpf.FileName);
                   // Compute thumbnail size.
                   Size thumbnailSize = GetThumbnailSize(image);
                   // Get thumbnail.
                   System.Drawing.Image thumbnail = image.GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, null, IntPtr.Zero);
                   // Save thumbnail.
                   thumbnail.Save(Server.MapPath(PhotoThumbFolder + hpf.FileName));
                   //////////// Get Photo Type Id////////
                   string PhotoTypeId = ab.GetTypeID("Photo");
                   /////////////Insert in to Album Table////////////
                   ab.InsertSinglePhotointoAlbum(PhotoTypeId, null, date, hpf.FileName);
                   //////////////Get Album ID from Album table/////////////////////
                   string AlbumId = ab.GetAlbumID(PhotoTypeId, date, hpf.FileName);
                   /////////////Insert in to status Table////////////
                   ab.InsertSlamBookStatus(null, AlbumId, null, null, null, null, null, UID, PhotoTypeId, null, date, null, null, null);

               }
           }

           // FileUpload1.PostedFile.SaveAs(Server.MapPath(PhotoFolder) + imgName);




       }


   }
   static Size GetThumbnailSize(System.Drawing.Image original)
   {
       // Maximum size of any dimension.
       const int maxPixels = 450;
       // Width and height.
       int originalWidth = original.Width;
       int originalHeight = original.Height;
       // Compute best factor to scale entire image based on larger dimension.
       double factor;
       if (originalWidth > originalHeight)
       {
           factor = (double)maxPixels / originalWidth;
       }
       else
       {
           factor = (double)maxPixels / originalHeight;
       }
       // Return thumbnail size.
       return new Size((int)(originalWidth * factor), (int)(originalHeight * factor));
   }
Posted

 
Share this answer
 
Comments
[no name] 2-Dec-13 2:44am    
thanks! a lot i utilize the links you have provided, i will upload my complete solution very soon
Thanks7872 2-Dec-13 2:45am    
Glad to help you :-)
i have posted my solution as codeproject tip. please refer to this tip
link
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900