locked
passing dyanamic path for images to Slideshow extender RRS feed

  • Question

  • User734806092 posted

    my .aspx code is as follows.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <style type="text/css">
            .style1
            {
                width: 100%;
            }
        </style>
       
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <table class="style1">
                <tr>
                    <td>
                        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
                        </asp:ToolkitScriptManager>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="txt_TeamName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="txt_ModuleName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:FileUpload ID="FileUpload1" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:Button ID="btn_view" runat="server" Text="View" />
                    </td>
                </tr>
                <tr>
                    <td>
                       <asp:Panel ID="Panel1" runat="server">
            <asp:ImageButton ID="ImageButton1" runat="server" />
            <asp:Image ID="Image1" runat="server" />
            <asp:ImageButton ID="ImageButton2" runat="server" />
             <br />
                <b>Name:</b>
                <asp:Label ID="lblImageTitle" runat="server" Text="Label" /><br />
                <b>Description:</b>
                <asp:Label ID="lblImageDescription" runat="server" Text="Label" />
            
        </asp:Panel> 
                    </td>
                </tr>
            </table>
         <asp:SlideShowExtender ID="SlideShowExtender1" ImageTitleLabelID="lblImageTitle" ImageDescriptionLabelID="lblImageDescription" SlideShowServiceMethod="GetImages" AutoPlay="true" PlayInterval="10000" PreviousButtonID="ImageButton1" TargetControlID="Image1" NextButtonID="ImageButton2" Loop="true" runat="server" >   
        </asp:SlideShowExtender>
        <asp:ModalPopupExtender ID="ModalPopupExtender1" TargetControlID="btn_view" CancelControlID="Button1" PopupControlID="Panel1" runat="server">
        </asp:ModalPopupExtender> 
        </div>
        </form>
    </body>
    </html>


     

    my .cs code is as follws...

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.SqlClient;
    using System.IO;
    using Microsoft.Office.Core;
    using Microsoft.Office.Interop;
    using AjaxControlToolkit;
    using System.Web.Services;
    using System.Web.Script.Services;
    using System.Collections.Generic;
    
    public partial class HomePage : System.Web.UI.Page
    {
        public SqlConnection con = new SqlConnection("Data Source=10.91.82.195;Initial Catalog=OPPRDashbaord;Integrated Security=True");
        public static string Filepath;
        public static string ImageFilePath;
        public string vFilePath;
        public string vImagePath;
        public static string vFileName;
        public string vModule;
        public string vTeamName;
        public string vUser;
        public static string vImagefromDB;
        public static string vPath;
        public static DataTable vDT=new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            
                if (!IsPostBack)
                {
                   
                }
                Filepath = @"C:\Documents and Settings\ade121\My Documents\Visual Studio 2008\WebSites\OPPR_Board\PPT";
                ImageFilePath = @"C:\Documents and Settings\ade121\My Documents\Visual Studio 2008\WebSites\OPPR_Board\Images";
              
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
           
            if (txt_TeamName.Text == "" || txt_TeamName.Text == null)
            {
                
            }
            else
            {
                CreateFolder();
               
            }
        }
        public void CreateFolder()
        {
            vTeamName = txt_TeamName.Text.TrimEnd().ToString();                                             // Getting a Team Name
            vModule = txt_ModuleName.Text.TrimEnd().ToString();                                             // Getting A module name
            vFileName = FileUpload1.FileName;                                                               // File Name
            
            vFilePath = Filepath + "\\" + vTeamName + "\\";                                       // file path
            vImagePath = ImageFilePath + "\\" + vTeamName+"\\";                                     // image Path
    
            /* File Directory */
            if (System.IO.Directory.Exists(vFilePath))
            {
                if (System.IO.Directory.Exists(Path.Combine(vFilePath + "\\", vModule)))
                {
                   
                }
                else
                {
                    System.IO.Directory.CreateDirectory(Path.Combine(Filepath + "\\" + vTeamName, vModule));             // creating folder for module in team folder
                   
                }
            }
            else
            {
                System.IO.Directory.CreateDirectory(Path.Combine(Filepath, vTeamName));                         // creating Folder for Team
                System.IO.Directory.CreateDirectory(Path.Combine(vFilePath, vModule));             // creating folder for module in team folder
               
            }
            
           // vFilePath = vFilePath +"\\"+ vModule;
            FileUpload1.SaveAs(Path.Combine(vFilePath,vModule)+"\\"+vFileName);               // Saving File
    
            /* Image Directory */
            if (System.IO.Directory.Exists(vImagePath))
            {
                if (System.IO.Directory.Exists(Path.Combine(vImagePath + "\\", vModule)))
                {
                    DirectoryInfo vDir = new DirectoryInfo(vImagePath + "\\" + vModule);
                   // vDir.Delete(true);
                    foreach (FileInfo vFi in vDir.GetFiles())
                    {
                        vFi.Delete();
                    }
                }
                else
                {
                    System.IO.Directory.CreateDirectory(Path.Combine(vImagePath, vModule));             // creating folder for module in team folder
                }
               
            }
            else
            {
                System.IO.Directory.CreateDirectory(Path.Combine(ImageFilePath, vTeamName));                         // creating Folder for Team
                System.IO.Directory.CreateDirectory(Path.Combine(vImagePath, vModule));             // creating folder for module in team folder
            }
            ConvertPPT_To_Images(Path.Combine(Path.Combine(vFilePath,vModule),vFileName),Path.Combine(vImagePath,vModule)+"\\");
    
            
        }
        private void ConvertPPT_To_Images(string sPPTFilePath, string sImagesDirectoryPath)
        {
    
            try
            {
                Microsoft.Office.Interop.PowerPoint.Application appPpt = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation objActivePresentation
                     = appPpt.Presentations.Open(sPPTFilePath,
                                                 Microsoft.Office.Core.MsoTriState.msoCTrue,
                                                 Microsoft.Office.Core.MsoTriState.msoTriStateMixed,
                                                 Microsoft.Office.Core.MsoTriState.msoFalse);
    
    
    
                //objActivePresentation.SaveAs(sImagesDirectoryPath, PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoFalse);
                //objActivePresentation.Export(sImagesDirectoryPath + @"\Slide1.png", "png", 960, 720);
                //objActivePresentation.SaveAs(sImagesDirectoryPath + "slide", PpSaveAsFileType.ppSaveAsTIF, MsoTriState.msoFalse);
                int i = 0;
                foreach (Microsoft.Office.Interop.PowerPoint.Slide objSlide in objActivePresentation.Slides)
                {
                    //Names are generated based on timestamp. 
                    //objSlide.Export("Slide" + i, "PNG", 960, 720);
                    //objSlide.Export(sImagesDirectoryPath + "Slide" + i + ".PNG", "PNG", 900, 600);
                    objSlide.Export(sImagesDirectoryPath + "" + vTeamName.ToUpper().ToString() + "" + "-" + "" + vModule.ToUpper().ToString() + "" + "-" + i + ".PNG", "PNG", 900, 600);
                    i++;
                }
                objActivePresentation.Close();
                appPpt.Quit();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
       
        
    
        [WebMethod]
        [ScriptMethod]
        public static Slide[] GetImages()
        {
            
            List<Slide> slides = new List<Slide>();
    
            string path = HttpContext.Current.Server.MapPath("~/images/");
            
            Uri pathUri = new Uri(path, UriKind.RelativeOrAbsolute);
            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                Uri filePathUri = new Uri(file, UriKind.RelativeOrAbsolute);
                slides.Add(new Slide
                {
                    Name = Path.GetFileNameWithoutExtension(file),
                    Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                    ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
                });
            }
            return slides.ToArray();
        }
    
    
       
    }
    

    i am saving path of image folder in database.

    i want to pass Dynamic path from database to GetImages.

    How to do i  ???

    i hv tried a lot but somehow its not working...

    plz reply as early as possible.

    waiting for replies..

     

    Monday, May 26, 2014 9:13 AM

Answers

  • User1918509225 posted

    Hi Ashu37,

    First ,please make sure that your webservice run very well.

    Second,Please  set a breakpoint on your server method "GetImages",point to me which line code occur error message.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 28, 2014 6:08 AM

All replies

  • User582086724 posted

    Hi..

    Refer the below link to show slide show using dynamuc url..

    http://vdsite.com/Articles/175/Create-Slideshow-using--SlideShowExtender-with-dynamic-URl-in-Asp.net

    Monday, May 26, 2014 12:59 PM
  • User1918509225 posted

    Hi Ashu37,

    Based on my understanding ,you have get the dynamic path from the database.

    Image you have a list to store the dynamic image path, just like below:

    List<string>  imageFolderPaths=GetFromDataBase();
    

    Since you are saving   paths of image folder in database

    Second, you need to iterate the list,then add it to the slide,just like below:

     List<Slide> slides = new List<Slide>();
    foreach(string imgpath in imageFolderPaths){
         string path = HttpContext.Current.Server.MapPath(imgpath);
            
            Uri pathUri = new Uri(path, UriKind.RelativeOrAbsolute);
            string[] files = Directory.GetFiles(path);
            foreach (string file in files)
            {
                Uri filePathUri = new Uri(file, UriKind.RelativeOrAbsolute);
                slides.Add(new Slide
                {
                    Name = Path.GetFileNameWithoutExtension(file),
                    Description = Path.GetFileNameWithoutExtension(file) + " Description.",
                    ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
                });
            }
    }
    return slides.ToArray();
    

    Best Regards,

    Kevin Shen.

    Tuesday, May 27, 2014 3:14 AM
  • User734806092 posted

    Thanks Kevin.

    its really helpful.

    However i am not getting how do i get image path stored in database to imageFolderPaths variable which is of List<string> type.

    could you please explain...

    Tuesday, May 27, 2014 5:05 AM
  • User1918509225 posted

    Hi Ashu37,

    For how to get the image path stored in the database into list ,i think you should use ado.net to connect to the database.

    and read the record ,insert it into the list collection.

     
     List<string> imageFolderPaths=new List<string>();
      using (SqlConnection connection = new SqlConnection(
                   connectionString))
        {
            connection.Open();
    
            string queryString="select path from imagePath";
            SqlCommand command = new SqlCommand(queryString, connection);
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                imageFolderPaths.Add(reader[0].ToString());
            }
        }
    

    More details about how to use retrieving data using datareader  ,please refer to link below:

    http://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx

    Best Regards,

    Kevin Shen.

    Tuesday, May 27, 2014 5:14 AM
  • User734806092 posted

    Hi kevin

    Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'GetImages' failed with the following error: System.NullReferenceException-- Object reference not set to an instance of an object.

     I am getting this error..

    Tuesday, May 27, 2014 5:53 AM
  • User1918509225 posted

    Hi Ashu37,

    First ,please make sure that your webservice run very well.

    Second,Please  set a breakpoint on your server method "GetImages",point to me which line code occur error message.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 28, 2014 6:08 AM