/*
         * Check existing entries in the Kentico CMS.
         * If file is not found according to the file path in the system, the entry will be removed.
         */
        public int RemoveOrphanEntry(int libraryId)
        {
            try
            {
                int count = 0;

                DataSet ds = MediaFileInfoProvider.GetMediaFiles("FileLibraryID=" + libraryId, "");
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        MediaFileInfo info = new MediaFileInfo(dr);
                        string filefullpath = _image_root_folder + "\\" + info.FilePath.Replace('/', '\\');

                        if (!File.Exists(filefullpath))
                        {
                            info.Delete();
                            count++;
                        }
                    }
                }

                return count;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Media Library Error : Remove Orphan Entry - {0}", ex.Message));
            }
        }