Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET

Binding Image Slider with ASP.NET having Image Upload Panel

Rate me:
Please Sign up or sign in to vote.
4.98/5 (28 votes)
7 May 2013CPOL4 min read 131.8K   10.8K   44  
This article is meant for binding image from backend with your favorite image slider.
  • Flex-Slider-With-Uploadpanel.zip
  • Flexslider_with_MasterPage.zip
    • Flexslider_with_MasterPage
      • _ReSharper.Flexslider_with_MasterPage
        • BuildScriptCache
          • .crc
          • .version
          • 9
            • 33eeeb22.dat
        • ConditionalNames
          • .crc
          • .version
          • 9
            • 6df7a51e.dat
        • JavaScriptCache
          • .crc
          • .version
          • 1
            • 5660a4a1.dat
          • 6
            • 5d3c42c6.dat
        • JbPdbInfo
        • JSTest
          • .crc
          • .version
          • 7
            • 27a5f07c.dat
        • ModuleIds.xml
        • MVC
          • .crc
          • .version
        • NamedArguments
          • .crc
          • .version
          • 3
            • 4506692.dat
        • PersistenIdIndex.bin
        • Resources
          • .crc
          • .version
        • SymbolCache.bin
        • TagPrefixes
          • .crc
          • .version
          • 6
            • 5d3c42c6.dat
        • TodoItems
          • .crc
          • .version
          • 0
            • 36281efb.dat
        • WebSymbols
          • .crc
          • .version
          • 3
            • 4506692.dat
        • WordIndex
          • .crc
          • .version
          • 9
            • 6df7a51e.dat
        • XmlIndex
          • Accessibility.xml
            • 59F683E5.bin
          • Microsoft.Build.Framework.4.0.0.0.Nullness.Generated.xml
            • 91BD6FD3.bin
          • Microsoft.Build.Framework.xml
            • 5B4D04B5.bin
          • Microsoft.Build.Tasks.v4.0.4.0.0.0.Nullness.Generated.xml
            • AB623953.bin
          • Microsoft.Build.Tasks.v4.0.xml
            • 390E8A25.bin
          • Microsoft.Build.Utilities.v4.0.4.0.0.0.Nullness.Generated.xml
            • 07D57913.bin
          • Microsoft.Build.Utilities.v4.0.xml
            • 1A2D939D.bin
          • Microsoft.CSharp.4.0.0.0.Nullness.Generated.xml
            • 10F25633.bin
          • Microsoft.CSharp.xml
            • 4DDA1CCA.bin
          • Microsoft.JScript.10.0.0.0.Nullness.Generated.xml
            • 47DE7F86.bin
          • Microsoft.JScript.xml
            • F74F3354.bin
          • Microsoft.Transactions.Bridge.4.0.0.0.Nullness.Generated.xml
            • CB57B7D3.bin
          • Microsoft.VisualBasic.10.0.0.0.Contracts.xml
            • 905D2256.bin
          • Microsoft.VisualBasic.10.0.0.0.Nullness.Generated.xml
            • 34A06846.bin
          • Microsoft.VisualBasic.10.0.0.0.Pure.xml
            • 90D5FE85.bin
          • Microsoft.VisualBasic.Activities.Compiler.10.0.0.0.Nullness.Generated.xml
            • 276128C6.bin
          • Microsoft.VisualBasic.xml
            • EE79FEBF.bin
          • Microsoft.VisualC.xml
            • 90D3ABE6.bin
          • Microsoft.Web.Infrastructure.xml
            • 73FE563B.bin
          • mscorlib.4.0.0.0.Contracts.xml
            • 0DED0883.bin
          • mscorlib.4.0.0.0.Interfaces.Nullness.Generated.xml
            • 620DC5CB.bin
          • mscorlib.4.0.0.0.Nullness.Generated.xml
            • 772ECBB3.bin
          • mscorlib.4.0.0.0.Pure.xml
            • 6572C670.bin
          • mscorlib.I18n.xml
            • 366D6FC8.bin
          • mscorlib.Nullness.Manual.xml
            • A029C282.bin
          • mscorlib.ValueFlow.xml
            • 4E59B0BF.bin
          • mscorlib.xml
            • 05998BE8.bin
            • 743ADB6C.bin
          • SMDiagnostics.4.0.0.0.Nullness.Generated.xml
            • 8E9945D3.bin
          • System.4.0.0.0.Contracts.xml
            • 7458FC03.bin
          • System.4.0.0.0.Nullness.Generated.xml
            • 5304AF33.bin
          • System.4.0.0.0.Pure.xml
            • 403889F0.bin
          • System.Activities.4.0.0.0.Nullness.Generated.xml
            • 679C2793.bin
          • System.Activities.DurableInstancing.4.0.0.0.Nullness.Generated.xml
            • 5B8A77D3.bin
          • System.Activities.DurableInstancing.xml
            • 04D57C40.bin
          • System.Activities.xml
            • 33E2C3AB.bin
          • System.ComponentModel.DataAnnotations.4.0.0.0.Nullness.Generated.xml
            • EB11BC93.bin
          • System.ComponentModel.DataAnnotations.I18n.xml
            • E1E89968.bin
          • System.ComponentModel.DataAnnotations.xml
            • B9A8C76A.bin
          • System.Configuration.4.0.0.0.Contracts.xml
            • 8AA99CC3.bin
          • System.Configuration.4.0.0.0.Nullness.Generated.xml
            • 5C04A9F3.bin
          • System.Configuration.4.0.0.0.Pure.xml
            • A30FD330.bin
          • System.Configuration.Install.4.0.0.0.Contracts.xml
            • F6158D63.bin
          • System.Configuration.Install.4.0.0.0.Nullness.Generated.xml
            • 28353B53.bin
          • System.Configuration.Install.xml
            • 7FB1C71F.bin
          • System.Configuration.xml
            • 092A1070.bin
          • System.Core.4.0.0.0.Contracts.xml
            • 9A69C6A3.bin
          • System.Core.4.0.0.0.Nullness.Generated.xml
            • 8E5F4293.bin
          • System.Core.4.0.0.0.Pure.xml
            • D7464B10.bin
          • System.Core.LinqTunnel.xml
            • 63F26974.bin
          • System.Core.Nullness.Manual.xml
            • 31BDD0E2.bin
          • System.Core.xml
            • 11686E5B.bin
          • System.Data.4.0.0.0.Contracts.xml
            • 68A7E423.bin
          • System.Data.4.0.0.0.Nullness.Generated.xml
            • 7A169013.bin
          • System.Data.4.0.0.0.Pure.xml
            • 595BF890.bin
          • System.Data.DataSetExtensions.4.0.0.0.Nullness.Generated.xml
            • DB866913.bin
          • System.Data.DataSetExtensions.I18n.xml
            • B16CE5E8.bin
          • System.Data.DataSetExtensions.xml
            • 4A8BA0A6.bin
          • System.Data.Entity.4.0.0.0.Nullness.Generated.xml
            • 30E64393.bin
          • System.Data.Entity.xml
            • 9398E105.bin
          • System.Data.I18n.xml
            • 51BDCCE8.bin
          • System.Data.Linq.4.0.0.0.Nullness.Generated.xml
            • 0D37D4F3.bin
          • System.Data.Linq.Attributes.xml
            • B77F6C29.bin
          • System.Data.Linq.I18n.xml
            • A25BD988.bin
          • System.Data.Linq.xml
            • B30DAF64.bin
          • System.Data.OracleClient.4.0.0.0.Nullness.Generated.xml
            • 9BDAABD3.bin
          • System.Data.OracleClient.xml
            • 27DDCE31.bin
          • System.Data.Services.Client.4.0.0.0.Nullness.Generated.xml
            • 60E09193.bin
          • System.Data.Services.Client.xml
            • 0B993FC7.bin
          • System.Data.Services.Design.4.0.0.0.Nullness.Generated.xml
            • FA189D13.bin
          • System.Data.Services.Design.xml
            • E842CE0C.bin
          • System.Data.SqlXml.4.0.0.0.Nullness.Generated.xml
            • B9F432D3.bin
          • System.Data.SqlXml.xml
            • 48CF6F29.bin
          • System.Data.xml
            • 7BF6DA70.bin
          • System.Deployment.4.0.0.0.Nullness.Generated.xml
            • B159D593.bin
          • System.Deployment.xml
            • CC017739.bin
          • System.Design.4.0.0.0.Nullness.Generated.xml
            • 97CA2CD3.bin
          • System.Design.xml
            • 66D504B2.bin
          • System.DirectoryServices.4.0.0.0.Nullness.Generated.xml
            • 494E7693.bin
          • System.DirectoryServices.Protocols.4.0.0.0.Nullness.Generated.xml
            • CFA46BF3.bin
          • System.DirectoryServices.Protocols.xml
            • A1B5E32C.bin
          • System.DirectoryServices.xml
            • 14397267.bin
          • System.Drawing.4.0.0.0.Contracts.xml
            • 90ED1C03.bin
          • System.Drawing.4.0.0.0.Nullness.Generated.xml
            • 283CCF33.bin
          • System.Drawing.4.0.0.0.Pure.xml
            • 07B8A9F0.bin
          • System.Drawing.Design.4.0.0.0.Nullness.Generated.xml
            • EFA69853.bin
          • System.Drawing.Design.xml
            • E232227C.bin
          • System.Drawing.xml
            • 2F425360.bin
          • System.Dynamic.4.0.0.0.Nullness.Generated.xml
            • 8CC52453.bin
          • System.EnterpriseServices.4.0.0.0.Nullness.Generated.xml
            • C42E9193.bin
          • System.EnterpriseServices.xml
            • 484CBB5B.bin
          • System.I18n.xml
            • E767B348.bin
          • System.IdentityModel.4.0.0.0.Nullness.Generated.xml
            • 912FB3D3.bin
          • System.IdentityModel.Selectors.4.0.0.0.Nullness.Generated.xml
            • 8D618DD3.bin
          • System.IdentityModel.Selectors.xml
            • 17C23871.bin
          • System.IdentityModel.xml
            • FCECB5D9.bin
          • System.Management.4.0.0.0.Nullness.Generated.xml
            • 3E6A0593.bin
          • System.Management.xml
            • 8DDFA253.bin
          • System.Messaging.4.0.0.0.Nullness.Generated.xml
            • C11917B3.bin
          • System.Messaging.xml
            • 4EE26F6E.bin
          • System.Nullness.Manual.xml
            • AC02D602.bin
          • System.Numerics.4.0.0.0.Nullness.Generated.xml
            • 0D729213.bin
          • System.Numerics.xml
            • F65D6778.bin
          • System.Runtime.Caching.4.0.0.0.Nullness.Generated.xml
            • 8BB7FA53.bin
          • System.Runtime.Caching.xml
            • 6E34C19B.bin
          • System.Runtime.DurableInstancing.4.0.0.0.Nullness.Generated.xml
            • 94C6B993.bin
          • System.Runtime.DurableInstancing.xml
            • 952CDDB7.bin
          • System.Runtime.Remoting.4.0.0.0.Nullness.Generated.xml
            • 5A03BD53.bin
          • System.Runtime.Remoting.xml
            • 99D48EF3.bin
          • System.Runtime.Serialization.4.0.0.0.Nullness.Generated.xml
            • 4774B3B3.bin
          • System.Runtime.Serialization.Attributes.xml
            • E749FA69.bin
          • System.Runtime.Serialization.Formatters.Soap.2.0.0.0.Contracts.xml
            • 6A729305.bin
          • System.Runtime.Serialization.Formatters.Soap.4.0.0.0.Contracts.xml
            • 4C2FB483.bin
          • System.Runtime.Serialization.Formatters.Soap.4.0.0.0.Nullness.Generated.xml
            • F932F7B3.bin
          • System.Runtime.Serialization.Formatters.Soap.xml
            • AC344D82.bin
          • System.Runtime.Serialization.xml
            • 014E8BDC.bin
          • System.Security.4.0.0.0.Contracts.xml
            • 203E41A3.bin
          • System.Security.4.0.0.0.Nullness.Generated.xml
            • F66E1D93.bin
          • System.Security.4.0.0.0.Pure.xml
            • 3CA1E610.bin
          • System.Security.xml
            • 55841E76.bin
          • System.ServiceModel.4.0.0.0.Nullness.Generated.xml
            • F77BB4D3.bin
          • System.ServiceModel.Activation.4.0.0.0.Nullness.Generated.xml
            • 98DDA2B3.bin
          • System.ServiceModel.Activation.xml
            • B91280C8.bin
          • System.ServiceModel.Activities.4.0.0.0.Nullness.Generated.xml
            • 7FF57E53.bin
          • System.ServiceModel.Activities.xml
            • AB91D397.bin
          • System.ServiceModel.Web.4.0.0.0.Nullness.Generated.xml
            • 3A483B53.bin
          • System.ServiceModel.Web.xml
            • AFCF614C.bin
          • System.ServiceModel.xml
            • 263DB992.bin
          • System.ServiceProcess.4.0.0.0.Nullness.Generated.xml
            • 359B1C13.bin
          • System.ServiceProcess.xml
            • 2335E116.bin
          • System.Transactions.4.0.0.0.Nullness.Generated.xml
            • 3921BF93.bin
          • System.Transactions.xml
            • A0E212F7.bin
          • System.Web.4.0.0.0.Contracts.xml
            • 9CAD0083.bin
          • System.Web.4.0.0.0.Nullness.Generated.xml
            • 4965C3B3.bin
          • System.Web.4.0.0.0.Pure.xml
            • 4657BE70.bin
          • System.Web.ApplicationServices.4.0.0.0.Nullness.Generated.xml
            • 3969B1B3.bin
          • System.Web.ApplicationServices.xml
            • 331D36EA.bin
          • System.Web.Attributes.xml
            • C91B0A69.bin
          • System.Web.DynamicData.4.0.0.0.Nullness.Generated.xml
            • EB87AD13.bin
          • System.Web.DynamicData.xml
            • DC2CFBFB.bin
          • System.Web.Entity.4.0.0.0.Nullness.Generated.xml
            • F4A1E313.bin
          • System.Web.Entity.xml
            • A8FBC385.bin
          • System.Web.Extensions.4.0.0.0.Nullness.Generated.xml
            • 73D10753.bin
          • System.Web.Extensions.xml
            • 1594D3F4.bin
          • System.Web.I18n.xml
            • DDDA67C8.bin
          • System.Web.RegularExpressions.xml
            • B6E517C5.bin
          • System.Web.Services.4.0.0.0.Nullness.Generated.xml
            • 30597093.bin
          • System.Web.Services.Attributes.xml
            • 336EB089.bin
          • System.Web.Services.xml
            • 057956D0.bin
          • System.Web.WebPages.Deployment.xml
            • 6542E029.bin
            • EF9CEDAA.bin
          • System.Web.xml
            • C4EB8CF0.bin
          • System.Windows.Forms.4.0.0.0.Contracts.xml
            • 0AA1AF83.bin
          • System.Windows.Forms.4.0.0.0.Nullness.Generated.xml
            • E30F52B3.bin
          • System.Windows.Forms.4.0.0.0.Pure.xml
            • FDE30D70.bin
          • System.Windows.Forms.I18n.xml
            • 4286B6C8.bin
          • System.Windows.Forms.Manual.xml
            • 4EEF7F3C.bin
          • System.Windows.Forms.xml
            • 628A07B4.bin
          • System.Workflow.Activities.4.0.0.0.Nullness.Generated.xml
            • 95C13873.bin
          • System.Workflow.Activities.xml
            • FB17DE96.bin
          • System.Workflow.ComponentModel.4.0.0.0.Nullness.Generated.xml
            • 43C7AB93.bin
          • System.Workflow.ComponentModel.xml
            • 8A0F9E9D.bin
          • System.Workflow.Runtime.4.0.0.0.Nullness.Generated.xml
            • 5F2A0F93.bin
          • System.Workflow.Runtime.xml
            • 32431EC1.bin
          • System.WorkflowServices.4.0.0.0.Nullness.Generated.xml
            • DC2BE493.bin
          • System.WorkflowServices.xml
            • 8E65A1DD.bin
          • System.Xaml.4.0.0.0.Nullness.Generated.xml
            • A8037753.bin
          • System.Xaml.Hosting.4.0.0.0.Nullness.Generated.xml
            • 66496553.bin
          • System.Xaml.xml
            • C4D1BFD8.bin
          • System.Xml.4.0.0.0.Contracts.xml
            • 53D95363.bin
          • System.Xml.4.0.0.0.Nullness.Generated.xml
            • DD97C153.bin
          • System.Xml.4.0.0.0.Pure.xml
            • 5A1C7B50.bin
          • System.Xml.Attributes.xml
            • 09EED2C9.bin
          • System.Xml.I18n.xml
            • 8B551FA8.bin
          • System.Xml.Linq.4.0.0.0.Contracts.xml
            • 0FA00AA3.bin
          • System.Xml.Linq.4.0.0.0.Nullness.Generated.xml
            • 0EE20693.bin
          • System.Xml.Linq.4.0.0.0.Pure.xml
            • 9C820F10.bin
          • System.Xml.Linq.I18n.xml
            • A5756368.bin
          • System.Xml.Linq.xml
            • AD7A27CD.bin
          • System.Xml.xml
            • 48B5EA79.bin
          • System.xml
            • 74BB9F68.bin
            • C3B3EEEE.bin
      • Flexslider_with_MasterPage.sln
      • Flexslider_with_MasterPage.suo
      • Flexslider_with_MasterPage
  • Flex-Slider-With-Uploadpanel-noexe.zip
  • Flexslider_with_MasterPage-noexe.zip
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Flex_Slider_With_Uploadpanel
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadImage();
        }

        private void LoadImage()
        {
            try
            {
                string imagePath = "~/Upload/BannerImage/";
                string imageSource = SiteBaseUrl + "Upload/BannerImage/";
                string PhotoFilePath = Server.MapPath(imagePath);
                string divSlider = @"<ul class='slides'>";
                string fileSlide = string.Empty;
                string fileName = string.Empty;

                DirectoryInfo di = new DirectoryInfo(PhotoFilePath);
                FileInfo[] rgFiles = di.GetFiles("*.*");
                foreach (FileInfo fi in rgFiles)
                {
                    fileSlide = @"<li><img src='";

                    fileSlide += imageSource + fi + "' /></li>";

                    divSlider += fileSlide;
                }

                divImageSlider.InnerHtml = divSlider + "</ul>";

            }
            catch (Exception ex)
            {
                //ShowErrorMsg("error", ex.Message);
            }
        }

        public static string SiteBaseUrl
        {
            get
            {
                //return ConfigurationManager.AppSettings["RootPath"].ToString(); 
                string orginalUrl = HttpContext.Current.Request.Url.AbsoluteUri;
                if (HttpContext.Current.Request.Url.Query.Length > 0)
                    orginalUrl = orginalUrl.Replace(HttpContext.Current.Request.Url.Query, string.Empty);

                return orginalUrl.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty) + ((HttpContext.Current.Request.ApplicationPath == "/" ? "" : HttpContext.Current.Request.ApplicationPath)) + '/';
            }

        }

        protected void btnUpload(object sender, EventArgs e)
        {
            if (CheckValidImage(fluImage))
            {
                fluImage.PostedFile.SaveAs(MapPath("~") + "/Upload/BannerImage/" + fluImage.FileName);
                ShowErrorMsg("success", "Image Uploaded Successfully");
            }
        }

        private bool CheckValidImage(FileUpload FileUploadImage)
        {
            string contentType;

            contentType = FileUploadImage.PostedFile.ContentType.ToLower();

            if (contentType == "image/jpg" || contentType == "image/png" || contentType == "image/jpeg" || contentType == "image/pjpeg")
            {

            }
            else
            {
                ShowErrorMsg("error", "Image format is not valid. Valid image formats are ( jpg, png, jpeg).");

                return false;
            }

            return true;
        }
        private void ShowErrorMsg(string _class, string _msg)
        {
            divMessage.Style.Value = "display:block;";
            divMessage.Attributes.Add("class", _class);
            divMessage.InnerHtml = _msg;
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer Cefalo
Bangladesh Bangladesh
Hi,

I am Palash Debnath. I have been working on windows technologies since 2008. I started with ASP.NET. Then I moved to Windows Form and from the last year I have been working with Windows 8 app development. Work with Windows 10 apps development as well. Now I have been working with Microsoft Azure. I have completed my Undergraduate from Khulna University of Engineering in Computer Science & Engineering. Currently working as a Senior Software Engineer at Cefalo.

Comments and Discussions