• Login

BETA! This feature is currently in beta and has not been released as a patch yet. Please stand by and wait for notification from the DNN Store.

Before using File Descriptions, you must understand the process explained in the previous section, Advanced Setup, as you'll need to utilize stored procedures and functions for it to work properly. Technically you can store your descriptions in one field, but this is NOT good practice.

<TextBox Id="FileDescriptions" Datafield="FileDescriptions" DataType="String" style="display: none" />


<rmg:xile
  Id="Files"
  DataField="Files"
  FileDescription="True"
  FileDescriptionTargetID="FileDescriptions"
  FileDescriptionMaxLength="50"
  FileDescriptionPlaceholder="Add a description...">
</rmg:xile>  
File Description Example

Notice the <TextBox /> that we've hidden directly above Xile. The FileDescriptionTargetID must point to this hidden TextBox. This is where Xile will store the descriptions for each file.

File descriptions are stored in a delimited format, but not a PIPE (|) like the file names, which is due to the fact that descriptions can contain such characters. Because of this, we used a very strange combination of delimiters that is very highly unlikely anyone would ever type them in on purpose.

For example, when a description is added, it is stored as such:

filename.jpg##!!!##Description##|||##filename2.jpg##!!!##Description

So the file name and description are separated with the double hash and triple exclamation points, and each set is separated by the double has and triple PIPE characters.

Understanding this, we can loop through these in a stored procedure and assign the appropriate descriptions to the file name. We strongly suggest using the UniqueFilename set to True when using descriptions. This just further eliminates any possibility of an issue.

Here's an example of how to insert records, keeping in mind that this section of the docs builds off of the previous section on Advanced Setup.

CREATE PROCEDURE [dbo].[RMG_Product_AddProduct]
     @Name NVARCHAR(50)
    ,@PrimaryImage NVARCHAR(150)
    ,@AdditionalImages NVARCHAR(MAX)
    ,@FileDescriptions NVARCHAR(MAX)
    
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @NewProductID INT
    
    INSERT INTO [RMG_Product] ([Name]) VALUES (@Name)
    SET @NewProductID = SCOPE_IDENTITY()
    IF @PrimaryImage IS NOT NULL
        BEGIN
          INSERT INTO RMG_Product_Image ( [ProductID], [Filename], [IsPrimary] ) VALUES ( @NewProductID, @PrimaryImage, 1 )        
        END
        
    -- Additional Images
    WHILE LEN(@AdditionalImages) > 0
      BEGIN
        INSERT INTO RMG_Product_Image ( 
          [ProductID]
         ,[Filename] 
          ) VALUES ( 
          @NewProductID
         ,LEFT(@AdditionalImages, CHARINDEX('|', @AdditionalImages+'|') -1) 
        )
        SET @AdditionalImages = STUFF(@AdditionalImages, 1, CHARINDEX('|', @AdditionalImages+'|'), '')
      END

      declare @filestring nvarchar(max)
      declare @filename nvarchar(100)
      declare @filedesc nvarchar(500)

      WHILE CHARINDEX('##!!!##', @FileDescriptions) > 0
        BEGIN
          set @filestring = LEFT(@FileDescriptions, CHARINDEX('##|||##', @FileDescriptions+'##|||##') -1)
          set @filename = LEFT(@filestring, CHARINDEX('##!!!##', @filestring+'##!!!##') -1)
          set @filedesc = RIGHT(@filestring, CHARINDEX('##!!!##', REVERSE(@filestring)) -1)

          UPDATE RMG_Product_Image SET Description = @filedesc
          WHERE [Filename] = @filename
          AND ProductID = @NewProductID

          set @FileDescriptions = STUFF(@FileDescriptions, 1, LEN(@filestring) + 7, '')	
        END
END
Creating a Record

When using the Edit Form, you'll also need to create another function:

CREATE FUNCTION [dbo].[udf_RMG_Product_GetFileDescriptions]
  (
    @ProductID INT
  )

RETURNS nvarchar(MAX)
AS
BEGIN
  DECLARE @Descriptions nvarchar(MAX)
  SELECT @Descriptions = COALESCE(@Descriptions + '##|||##', '') + [Filename] + '##!!!##' + [Description]
  FROM RMG_Product_Image 
  WHERE ProductID = @ProductID 
  AND [Description] is not null             

RETURN @Descriptions
END
Scalar-Function for Descriptions

Then you can use this function to turn your file descriptions back into the delimited list, which is what Xile needs. For example your select command in your edit form would look like this:

SELECT    
  [Name]
  ,dbo.udf_RMG_Product_GetImages(@ProductID) AS AdditionalImages
  ,dbo.udf_RMG_Product_GetImageDescriptions(@ProductID) AS ImageDescriptions
  ,[ProductID]

FROM RMG_Product WHERE ProductID = @ProductID
Select Command Example

Last but not least, your update stored procedure:

CREATE PROCEDURE [dbo].[RMG_Product_UpdateProduct]
   @Name NVARCHAR(150)
  ,@AdditionalImages NVARCHAR(MAX)
  ,@FileDescriptions nvarchar(MAX)
  ,@ProductID INT

AS
BEGIN
SET NOCOUNT ON

UPDATE [RMG_Product] SET [Name]=@Name    
WHERE ProductID = @ProductID            


-- Additional Images
DELETE FROM RMG_Product_Image WHERE ProductID = @ProductID
WHILE LEN(@AdditionalImages) > 0
  BEGIN
    INSERT INTO RMG_Product_Image ( 
       [ProductID]
      ,[Filename] 
      ) VALUES ( 
       @ProductID
      ,LEFT(@AdditionalImages, CHARINDEX('|', @AdditionalImages+'|') -1) 
    )

    SET @AdditionalImages = STUFF(@AdditionalImages, 1, CHARINDEX('|', @AdditionalImages+'|'), '')
  END

  declare @filestring nvarchar(max)
  declare @filename nvarchar(100)
  declare @filedesc nvarchar(500)

WHILE CHARINDEX('##!!!##', @FileDescriptions) > 0
  BEGIN
    set @filestring = LEFT(@FileDescriptions, CHARINDEX('##|||##', @FileDescriptions+'##|||##') -1)
    set @filename = LEFT(@filestring, CHARINDEX('##!!!##', @filestring+'##!!!##') -1)
    set @filedesc = RIGHT(@filestring, CHARINDEX('##!!!##', REVERSE(@filestring)) -1)

    UPDATE RMG_Product_Image SET Description = @filedesc
    WHERE [Filename] = @filename
    AND ProductID = @ProductID

    set @FileDescriptions = STUFF(@FileDescriptions, 1, LEN(@filestring) + 7, '')	
  END
END
Update Procedure Example