Using C # how can I programmatically check if a folder exists in my report server
I've spent hours searching, but without any success.
I am programmatically creating report snapshots in SSRS using C # which creates report folders. The reports are generated in these folders, but to prevent errors from occurring, I delete the entire folder structure and then re-generate the reports to eliminate the SSRS exception.
I am using ReportingService2010.
ReportingService2010.DeleteItem(deleteFolderPath);
...
ReportingService2010.CreateFolder(folder, parentFolder, null);
- This is the line where I need to check if the folder and report exist
var ret = CheckExist(linkedReportName, newParent);
var param = GetReportParameters(existingReportPath);
ReportingService2010.SetItemParameters(existingReportPath, param);
- If I do not remove the folder structure, an error will be thrown after that in try / Catch
ReportingService2010.CreateLinkedItem(linkedReportName, newParent, existingReportPath, props);
I need to add a method to see if the report and report folder has already been created
source to share
Another possible alternative is to work directly with the path, type, and parentid fields in the Catalog table in the report server database. If you open up SQL Server and look at the table, it should be pretty clear what you need to do.
You can use C # to run a SQL command like
SELECT COUNT(*) FROM CATALOG WHERE PATH LIKE '%TheFolderNameImLookingFor%'
If the counter is greater than zero, the folder exists.
You can change this to suit your needs. Folder items are of type 1; Report items are of type 2, so you can use that to differentiate between reports and folders.
source to share
I think the best way is ReportService2010.GetItemType () . This returns the string ( ReportingService2010.ListItemTypes () method, including possible values "Unknown"
for nonexistent (instead of throwing an exception) or "Folder"
for a folder.
source to share
Directory.Exists () might work for you.
if (Directory.Exists(folderString))
{
// Do something
}
Don't forget the namespace System.IO
:
using System.IO;
UPDATE . In the future, if you are looking for a file, you can do the same with File.Exists()
, which is also in the namespace System.IO
.