question

1023-0602 avatar image
1 Vote"
1023-0602 asked OlafHelper-2800 answered

Search *.rdl file in multiple folders and upload to SSRS.

Hello,

I have code that downloads all *.rdl files from a folder and sends them to the report server.
I would like my code to look for files in subfolders and then reflected it to the server.

 public class ReportAutoSync
     {
         public FileInfo[] GetReportsFiles(string ReportsFolderPath)
         {
             List<FileInfo> files = new List<FileInfo>();
             DirectoryInfo d = new DirectoryInfo(ReportsFolderPath);
             FileInfo[] Files = d.GetFiles("*.rdl");
             return Files;
         }
    
         public void PublishReports(FileInfo[] reports, ref ReportingService2010SoapClient rs)
         {
             rs.ClientCredentials.UserName.UserName = "userName";
             rs.ClientCredentials.UserName.Password = "Password";
             var trustedHeader = new TrustedUserHeader(); ;
    
              Warning[] Warnings = null;
             foreach (FileInfo ReportFile in reports)
             {
                 Byte[] definition = null;
                 Warning[] warnings = null;
    
                 try
                 {
                     FileStream stream = ReportFile.OpenRead();
                     definition = new Byte[stream.Length];
                     var test = ReportFile.Directory;
                     stream.Read(definition, 0, (int)stream.Length);
                     stream.Close();
                 }
    
                 catch (IOException e)
                 {
                     Console.WriteLine(e.Message);
                 }
    
                 try
                 {
                     var request = new CreateCatalogItemRequest(null, "Report", ReportFile.Name, "/destination", true, definition, null);
                     var report = rs.CreateCatalogItemAsync(request);
    
                     if (report != null)
                     {
                         Console.WriteLine(ReportFile.Name + " Published Successfully ");
                         Console.WriteLine(string.Format("\n"));
                     }
                     if (warnings != null)
                     {
                         foreach (Warning warning in warnings)
                         {
                             Console.WriteLine(string.Format("Report: {0} has warnings", warning.Message));
                             Console.WriteLine(string.Format("\n"));
                         }
                     }
                     else
                         Console.WriteLine(string.Format
                              ("Report: {0} created successfully with no warnings", ReportFile.Name));
                     Console.WriteLine(string.Format("\n"));
                 }
    
                 catch (IOException e)
                 {
                     Console.WriteLine(e.Message);
                 }
             }
         }
     }
sql-server-reporting-services
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered

FileInfo[] Files = d.GetFiles("*.rdl");

You can use the SearchOption Enum => AllDirectories for the GetFiles methode to include all subdirectories as well

 FileInfo[] Files = d.GetFiles("*.rdl", SearchOption.AllDirectories);



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Joyzhao-MSFT avatar image
0 Votes"
Joyzhao-MSFT answered Joyzhao-MSFT edited

Hi @1023-0602 ,
I am sorry that it is beyond my ability. You could consult such issues in this forum and get help:https://github.com/features/code-review/
Best Regards,
Joy


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.