ReportingServicesBatchUpload.ReportingServicesUploader.UploadResource C# (CSharp) Method

UploadResource() public method

Uploads new .rdl file to SSRS
public UploadResource ( string resourceName, string filePath, string serverFolder, bool overwrite ) : IEnumerable
resourceName string
filePath string
serverFolder string
overwrite bool
return IEnumerable
        public IEnumerable<string> UploadResource(string resourceName, string filePath, string serverFolder, bool overwrite)
        {
            Byte[] definition = Initialize(filePath);

            try {
                _WebService.CreateResource(resourceName, serverFolder, overwrite, definition, GetMimeTypeFromFileName(resourceName), null);
            }
            catch (System.Web.Services.Protocols.SoapException) {

            }
            catch (NotSupportedException) {
                return new string[] { string.Format("File type is not supported") };
            }

            return null;
        }

Usage Example

Example #1
0
        private static void ProcessDirectory(string directory, string serverFolder, string url, bool overwrite)
        {
            var uploader = new ReportingServicesUploader();

            uploader.ReportingServicesWebServiceUrl = string.Format("{0}", url);

            IList <System.IO.FileInfo> files = new List <System.IO.FileInfo>();

            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(directory);
            foreach (var file in dir.GetFiles("*.rds"))
            {
                files.Add(file);
            }
            foreach (var file in dir.GetFiles())
            {
                if (file.Extension.ToLowerInvariant() != ".rds")
                {
                    files.Add(file);
                }
            }

            foreach (var file in files)
            {
                Console.WriteLine("Processing file {0}", file.Name);
                string reportName             = file.Name.Remove(file.Name.Length - 4);
                IEnumerable <string> warnings = null;
                switch (file.Extension.ToLowerInvariant())
                {
                case ".bmp":
                case ".jpg":
                case ".png":
                    warnings = uploader.UploadResource(file.Name, file.FullName, serverFolder, overwrite);
                    break;

                case ".rds":
                    warnings = uploader.UploadDataSource(file.FullName, serverFolder, overwrite);
                    break;

                case ".rdl":
                    warnings = uploader.UploadReport(file.Name.Remove(file.Name.Length - 4), file.FullName, serverFolder, overwrite);
                    break;

                default:
                    Console.WriteLine("\tFile type unknown.  Skipping");
                    break;
                }

                if (warnings != null)
                {
                    foreach (var warning in warnings)
                    {
                        Console.Error.WriteLine("\tWarning: {0}", warning);
                    }
                }
            }
        }
All Usage Examples Of ReportingServicesBatchUpload.ReportingServicesUploader::UploadResource