/// <summary>
    /// Returns next file name for import.
    /// </summary>
    private string GetNextFileName()
    {
        string nextFileName;
        int    indexOfDel = ImportFilePaths.IndexOf('|');

        if (indexOfDel >= 0)
        {
            nextFileName = ImportFilePaths.Substring(0, indexOfDel);
        }
        else
        {
            // Last file name
            nextFileName = ImportFilePaths.Trim();
        }
        return(nextFileName);
    }
    /// <summary>
    /// Handle storing single media file info into the DB.
    /// </summary>
    private void HandleSingleMediaFile()
    {
        string fileName = txtImportFileName.Text.Trim();

        // Check if the filename is in correct format
        if (!ValidationHelper.IsFileName(fileName))
        {
            SetupTexts();

            // Inform user on error
            RaiseOnAction("importerror", GetString("media.rename.wrongformat"));
            return;
        }

        // Get info on current file path
        string currFileName = GetNextFileName();

        if (!String.IsNullOrEmpty(currFileName))
        {
            string ext = Path.GetExtension(currFileName);
            if (!MediaLibraryHelper.IsExtensionAllowed(ext.TrimStart('.')))
            {
                RaiseOnAction("importerror", string.Format(GetString("attach.notallowedextension"), ext, MediaLibraryHelper.GetAllowedExtensions(SiteName).TrimEnd(';').Replace(";", ", ")));
                return;
            }
        }

        try
        {
            // Get info on current file path
            if (!String.IsNullOrEmpty(currFileName))
            {
                string filePath = (string.IsNullOrEmpty(FolderPath)) ? currFileName : DirectoryHelper.CombinePath(FolderPath, currFileName);

                // Get file and library info
                FileInfo currFile = FileInfo.New(MediaFileInfoProvider.GetMediaFilePath(SiteName, LibraryInfo.LibraryFolder, filePath));
                if (currFile != null)
                {
                    // Save media file info on current file
                    RaiseOnSaveRequired(currFile, txtImportFileTitle.Text.Trim(), txtImportFileDescription.Text.Trim(), URLHelper.GetSafeFileName(fileName, SiteName, false), filePath);
                }
            }

            // Update file paths set and store updated version in the ViewState
            int indexOfDel = ImportFilePaths.IndexOf('|');
            ImportFilePaths = (indexOfDel > 0 ? ImportFilePaths.Remove(0, indexOfDel + 1) : String.Empty);

            bool wasLast = String.IsNullOrEmpty(ImportFilePaths);
            if (wasLast)
            {
                FinishImport();
            }
            else
            {
                RaiseOnAction("singlefileimported", null);

                // Increment current file index
                ImportCurrFileIndex++;
            }
        }
        catch (Exception ex)
        {
            SetupTexts();

            // Inform user on error
            RaiseOnAction("importerror", ex.Message);
        }
        finally
        {
            SetupImport();
        }
    }
    /// <summary>
    /// Handle storing single media file info into the DB.
    /// </summary>
    private void HandleSingleMediaFile()
    {
        string fileName = this.txtImportFileName.Text.Trim();

        // Check if the filename is in correct format
        if (!ValidationHelper.IsFileName(fileName))
        {
            SetupTexts();

            // Inform user on error
            RaiseOnAction("importerror", GetString("media.rename.wrongformat"));
            return;
        }

        bool wasLast = false;

        try
        {
            // Get info on current file path
            string currFileName = GetNextFileName();
            if (!String.IsNullOrEmpty(currFileName))
            {
                string filePath = (string.IsNullOrEmpty(this.FolderPath)) ? currFileName : DirectoryHelper.CombinePath(this.FolderPath, currFileName);

                // Get file and library info
                FileInfo currFile = FileInfo.New(MediaFileInfoProvider.GetMediaFilePath(CMSContext.CurrentSiteName, this.LibraryInfo.LibraryFolder, filePath));
                if (currFile != null)
                {
                    // Save media file info on current file
                    RaiseOnSaveRequired(currFile, this.txtImportFileTitle.Text.Trim(), this.txtImportFileDescription.Text.Trim(), URLHelper.GetSafeFileName(fileName, CMSContext.CurrentSiteName, false), filePath);
                }
            }
            else
            {
                wasLast = true;
            }

            // Update file paths set and store updated version in the ViewState
            int indexOfDel = ImportFilePaths.IndexOf("|");
            ImportFilePaths = (indexOfDel > 0 ? ImportFilePaths.Remove(0, indexOfDel + 1) : String.Empty);

            wasLast = String.IsNullOrEmpty(ImportFilePaths);
            if (wasLast)
            {
                FinishImport();
                return;
            }
            else
            {
                RaiseOnAction("singlefileimported", null);

                // Increment current file index
                this.ImportCurrFileIndex++;
            }
        }
        catch (Exception ex)
        {
            SetupTexts();

            // Inform user on error
            RaiseOnAction("importerror", ex.Message);
        }
        finally
        {
            SetupImport();
        }
    }