locked
How to show filesystem(filenames from a folder) in SSRS RRS feed

  • Question

  • Hallo everyone,

    I haved already tried the following solutions

    http://forums.asp.net/t/1422162.aspx?System+Security+SecurityException+Request+for+the+permission+of+type+System+Security+Permissions+FileIOPermission+mscorlib+Version+2+0+0+0+Culture+neutral+PublicKeyToken+b77a5c561934e089+failed+

    AND

    http://stackoverflow.com/questions/8476231/ssrs-custom-code

    Both didn't work.

    My problem is:

    What I want is to show all filenames from a certain folder in SSRS.

    I started with custom code in SSRS:

    Public Function getArrayOfFilename(pathname As String) as Array
    
            Dim arrayOfFilename As String() = System.IO.Directory.GetFiles(pathname)
    
            System.Array.Sort(Of String)(arrayOfFilename)
    
            Return arrayOfFilename
    
    End Function

    My questions are:

    1. If I try to call this function in a textbox like this:

    getArrayOfFilename("C:\Help\")

    then I get this error:

    [rsRuntimeErrorInExpression] The Value expression for the textrun ‘Textbox8.Paragraphs[0].TextRuns[0]’ contains an error: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    2. Can I use this array as a dataset to carete a list or table  in SSRS?

    Thanks for any hint!


    • Edited by cecilfang Wednesday, February 4, 2015 9:46 AM
    Wednesday, February 4, 2015 9:38 AM

Answers

  • The error message is related to permission. You are trying to access the file system object of the reporting server.

    Moreover creating a dataset from a custom code can be challenge, instead we can simply use TSQL to do this.

    ----------------- RUN TO ENABLE COMMAND SHELL
    EXEC sp_configure 'xp_cmdshell', 1;
    GO
    -- To update the currently configured value for this feature.
    RECONFIGURE;
    ----------------------QUERY
    DECLARE @folder VARCHAR(100) = 'C:\TESTING'
    DECLARE @DOSCommand varchar(1024); SET @DOSCommand =  'dir ' + @folder +'\'  + ' /A-D  /B'
    EXEC MASTER.dbo.xp_cmdshell @DOSCommand


    Regards, RSingh

    • Proposed as answer by Valentino Vranken Wednesday, February 4, 2015 2:32 PM
    • Marked as answer by Wendy Fu Thursday, February 5, 2015 1:53 AM
    Wednesday, February 4, 2015 11:38 AM

All replies

  • The error message is related to permission. You are trying to access the file system object of the reporting server.

    Moreover creating a dataset from a custom code can be challenge, instead we can simply use TSQL to do this.

    ----------------- RUN TO ENABLE COMMAND SHELL
    EXEC sp_configure 'xp_cmdshell', 1;
    GO
    -- To update the currently configured value for this feature.
    RECONFIGURE;
    ----------------------QUERY
    DECLARE @folder VARCHAR(100) = 'C:\TESTING'
    DECLARE @DOSCommand varchar(1024); SET @DOSCommand =  'dir ' + @folder +'\'  + ' /A-D  /B'
    EXEC MASTER.dbo.xp_cmdshell @DOSCommand


    Regards, RSingh

    • Proposed as answer by Valentino Vranken Wednesday, February 4, 2015 2:32 PM
    • Marked as answer by Wendy Fu Thursday, February 5, 2015 1:53 AM
    Wednesday, February 4, 2015 11:38 AM
  • Thanks, it seems to work.
    Wednesday, February 4, 2015 1:15 PM
  • thank you!
    Wednesday, February 4, 2015 1:16 PM