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);
}
}
}
}