protected void rptFileList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if(e.CommandName == "Download")
        {
            Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
            Response.AppendHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(e.CommandArgument.ToString()));

            Response.WriteFile(e.CommandArgument.ToString());
        }
        else if(e.CommandName == "Delete")
        {
            string file = e.CommandArgument.ToString();
            if(File.Exists(file))
            {
                File.Delete(file);

                string xmlDir = Path.Combine(AppUtil.GetUploadFolderForXml(), Path.GetFileNameWithoutExtension(file));
                Directory.Delete(xmlDir,true);

                //ChapterDefinitionFile chapterFile = ChapterFileManager.Instance.GetByFileName(Path.GetFileName(file));
                ContentFileManager manager = new ContentFileManager();
                ContentFile chapterFile = manager.GetByFileName(Path.GetFileName(file));
                if (chapterFile != null)
                {
                    //ChapterFileManager.Instance.Delete(chapterFile);
                    manager.Delete(chapterFile);
                }
            }
        }

        BindFileList();
    }
    protected void rptFileList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        RepeaterItem item = e.Item;
        if ((item.ItemType == ListItemType.Item) ||
            (item.ItemType == ListItemType.AlternatingItem))
        {
            string file = e.Item.DataItem as string;

            string fileName = Path.GetFileName(file);
            //ChapterDefinitionFile chapterFile = ChapterFileManager.Instance.GetByFileName(fileName);
            ContentFileManager manager = new ContentFileManager();
            ContentFile chapterFile = manager.GetByFileName(fileName);

            Label lblFileName = e.Item.FindControl("lblFile") as Label;
            LinkButton hplDownload = e.Item.FindControl("hplDownload") as LinkButton;
            LinkButton hplDelete = e.Item.FindControl("hplDelete") as LinkButton;
            HyperLink hplChapters = e.Item.FindControl("hplChapters") as HyperLink;

            if (chapterFile != null)
            {
                lblFileName.Text = Path.GetFileName(file);
                hplDownload.CommandArgument = file;
                hplDelete.CommandArgument = file;

                hplChapters.NavigateUrl = string.Format("~/Pages/Public/ViewChapters.aspx?FileId={0}", chapterFile.FileID);
            }
            else
            {
                lblFileName.Visible = false;
                hplDelete.Visible = false;
                hplDownload.Visible = false;
                hplChapters.Visible = false;
            }
        }
    }
    private void TrackViewInfo(long fileID)
    {
        ContentFileManager fileManager = new ContentFileManager();
        ContentFile file = fileManager.GetByID(fileID);
        if (file != null && SessionCache.CurrentUser != null)
        {
            FileTracking tracking = new FileTracking();
            tracking.UserID = SessionCache.CurrentUser.UserID;
            tracking.UserIP = AppUtil.GetRemoteIPAddress();
            tracking.FileID = fileID;
            tracking.IsViewed = true;
            tracking.IsDownloaded = false;

            FileTrackingManager manager = new FileTrackingManager();
            manager.Save(tracking);
        }
    }
    protected void uploadBtn_Click(object o, EventArgs e)
    {
        // try save the file to the web server
        if (filename.PostedFile != null)
        {
            string sPath = AppUtil.GetUploadFolderForExel();
            if (!Directory.Exists(sPath))
            {
                Directory.CreateDirectory(sPath);
            }
            //build file info for display
            string sFileInfo =
                "<br>FileName: " +
                filename.PostedFile.FileName;

            try
            {
                string formattedFileName = Path.GetFileName(filename.PostedFile.FileName).Replace(" ","_");
                filename.PostedFile.SaveAs(System.IO.Path.Combine(sPath, formattedFileName));

                //ChapterDefinitionFile file = ChapterFileManager.Instance.GetByFileName(formattedFileName);
                //if (file == null)
                //{
                //    file = new ChapterDefinitionFile();
                //    file.FileName = formattedFileName;
                //}

                //ChapterFileManager.Instance.Save(file);

                ///Save File Info
                ContentFileManager fileManager = new ContentFileManager();
                ContentFile file = fileManager.GetByFileName(formattedFileName);
                if (file == null)
                {
                    file = new ContentFile();
                    file.FileName = formattedFileName;
                    file.UploadedBy = string.IsNullOrEmpty(this.Page.User.Identity.Name)?"Admin":this.Page.User.Identity.Name;
                    file.UploadedOn = DateTime.Now;
                    file.Modified = DateTime.Now;
                    file.FileCategoryID = 1;///Video File
                    fileManager.Save(file);
                }

                string filePath = Path.Combine(AppUtil.GetUploadFolderForExel(), file.FileName);
                string xmlDir = AppUtil.GetUploadFolderForXml();

                List<VideoSectionItem> videoSectionItems = ExelHelper.Instance.GetDataFromExcel(filePath);
                int levelCount = ExelHelper.Instance.GetLevelCount(videoSectionItems);
                List<VideoSectionItem> items = DataParser.Instance.GetHirararchialVideoSectionItems(videoSectionItems, xmlDir, levelCount, file.FileName);

                string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.FileName);
                DeleteExistingFiles(fileNameWithoutExtension);
                XmlHelper.Instance.WriteXmlsForItems(fileNameWithoutExtension, fileNameWithoutExtension, items, 0);

                status.InnerText = "File uploaded successfully.";

                ((App.Util.PageBase)this.Page).SignalFileUploaded();

            }
            catch (Exception exc)
            {
                status.InnerText = "Failed to upload file.";
                throw exc;
            }
        }
    }