private void CreateLinkedReport(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode , HttpClientCredentialType ReportHttpClientCredentialType , string ReportFolder, string ReportName , string LinkedReportPath , ReportingService2010.Property[] LinkedReportProperties , XElement xLinkedReportParameters //, string ParameterLanguage ) { string serviceUrl; string execUrl; BasicHttpBinding basicHttpBinding; ConfigureReportServerBinding(ReportServerPath, ReportMode, ReportHttpClientCredentialType, out serviceUrl, out execUrl, out basicHttpBinding); using (ReportingService2010.ReportingService2010SoapClient rsService = new ReportingService2010.ReportingService2010SoapClient(basicHttpBinding, new EndpointAddress(serviceUrl))) { ReportingService2010.TrustedUserHeader trusteduserHeader; ReportExecution2005.TrustedUserHeader userHeader; GetHeaders(UserName, UserPassword, rsService, null, out trusteduserHeader, out userHeader); ReportingService2010.SearchCondition condition = new ReportingService2010.SearchCondition(); condition.Condition = ReportingService2010.ConditionEnum.Equals; condition.ConditionSpecified = true; condition.Name = "Name"; ReportingService2010.SearchCondition[] conditions = new ReportingService2010.SearchCondition[1]; conditions[0] = condition; ReportingService2010.CatalogItem[] foundItems = null; condition.Values = new string[] { ReportName.TrimStart('/').TrimEnd('/') }; rsService.FindItems(trusteduserHeader , "/" + ReportFolder.TrimStart('/').TrimEnd('/') , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundItems); if (foundItems != null && foundItems.Count() > 0) { foreach (var item in foundItems) { if (item.Path == "/" + ReportFolder.TrimStart('/').TrimEnd('/') + "/" + ReportName) { string parentReportPath = item.Path; try { string linkedReportName = LinkedReportPath.Substring(LinkedReportPath.LastIndexOf('/') + 1).TrimStart('/').TrimEnd('/'); string linkedReportFolderPath = LinkedReportPath.Substring(0, LinkedReportPath.LastIndexOf('/')).TrimEnd('/'); CheckLinkedFolderExists(rsService, trusteduserHeader, condition, conditions, linkedReportFolderPath); ReportingService2010.CatalogItem[] foundLinkedItems = null; condition.Values = new string[] { linkedReportName }; rsService.FindItems(trusteduserHeader , linkedReportFolderPath , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundLinkedItems); if (foundLinkedItems == null || (foundLinkedItems != null && foundLinkedItems.Count() == 0)) { rsService.CreateLinkedItem(trusteduserHeader , linkedReportName , linkedReportFolderPath , parentReportPath , LinkedReportProperties); } if (xLinkedReportParameters != null) { //// List of properties to copy from parent to linked reports. ??? //var requestedProperties = new ReportingService2010.Property[] { // new ReportingService2010.Property { Name = "PageHeight" }, // new ReportingService2010.Property { Name = "PageWidth" }, // new ReportingService2010.Property { Name = "TopMargin" }, // new ReportingService2010.Property { Name = "BottomMargin" }, // new ReportingService2010.Property { Name = "LeftMargin" }, // new ReportingService2010.Property { Name = "RightMargin" } //}; IEnumerable<XElement> linkedReportParams = xLinkedReportParameters.Descendants("Param"); if (linkedReportParams.Count() > 0) { List<ReportingService2010.ItemParameter> ItemParamsList = new List<ReportingService2010.ItemParameter>(); foreach (var linkedReportParam in linkedReportParams) { string defaultValues = linkedReportParam.Attribute("DefaultValues").Value; if (!string.IsNullOrEmpty(defaultValues)) { ReportingService2010.ItemParameter[] parentReportParams = null; rsService.GetItemParameters(trusteduserHeader , parentReportPath , null , false, null, null, out parentReportParams); bool paramExists = false; ReportingService2010.ItemParameter ip = new ReportingService2010.ItemParameter(); ip.Name = linkedReportParam.Attribute("Name").Value; foreach (var parentReportParam in parentReportParams) { if (parentReportParam.Name == ip.Name) { ip.AllowBlank = parentReportParam.AllowBlank; ip.MultiValue = parentReportParam.MultiValue; ip.Nullable = parentReportParam.Nullable; ip.Prompt = parentReportParam.Prompt; ip.PromptUser = parentReportParam.PromptUser; ip.PromptUserSpecified = parentReportParam.PromptUserSpecified; paramExists = true; break; } } if (paramExists) { ip.DefaultValues = defaultValues.Split(','); if (linkedReportParam.Attribute("Hide") != null && linkedReportParam.Attribute("Hide").Value.ToLower() == "true") { //hide the paramerter using combination of parameters. There is no Hide property which reflects UI Hide checkbox ip.PromptUser = false; ip.PromptUserSpecified = false; ip.Prompt = null; } ItemParamsList.Add(ip); } } } rsService.SetItemParameters(trusteduserHeader, LinkedReportPath, ItemParamsList.ToArray()); } } } catch (SoapException ex) { LogMessage("Not able to create linked report " + LinkedReportPath + " Error: " + ex.Message); throw; } break; } } } } }
private void CreateLinkedReport(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode , HttpClientCredentialType ReportHttpClientCredentialType , string ReportFolder, string ReportName , string LinkedReportPath , ReportingService2010.Property[] LinkedReportProperties , XElement xLinkedReportParameters //, string ParameterLanguage ) { string serviceUrl; string execUrl; BasicHttpBinding basicHttpBinding; ConfigureReportServerBinding(ReportServerPath, ReportMode, ReportHttpClientCredentialType, out serviceUrl, out execUrl, out basicHttpBinding); using (ReportingService2010.ReportingService2010SoapClient rsService = new ReportingService2010.ReportingService2010SoapClient(basicHttpBinding, new EndpointAddress(serviceUrl))) { ReportingService2010.TrustedUserHeader trusteduserHeader; ReportExecution2005.TrustedUserHeader userHeader; GetHeaders(UserName, UserPassword, rsService, null, out trusteduserHeader, out userHeader); ReportingService2010.SearchCondition condition = new ReportingService2010.SearchCondition(); condition.Condition = ReportingService2010.ConditionEnum.Equals; condition.ConditionSpecified = true; condition.Name = "Name"; ReportingService2010.SearchCondition[] conditions = new ReportingService2010.SearchCondition[1]; conditions[0] = condition; ReportingService2010.CatalogItem[] foundItems = null; condition.Values = new string[] { ReportName.TrimStart('/').TrimEnd('/') }; rsService.FindItems(trusteduserHeader , "/" + ReportFolder.TrimStart('/').TrimEnd('/') , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundItems); if (foundItems != null && foundItems.Count() > 0) { foreach (var item in foundItems) { if (item.Path == "/" + ReportFolder.TrimStart('/').TrimEnd('/') + "/" + ReportName) { string parentReportPath = item.Path; try { string linkedReportName = LinkedReportPath.Substring(LinkedReportPath.LastIndexOf('/') + 1).TrimStart('/').TrimEnd('/'); string linkedReportFolderPath = LinkedReportPath.Substring(0, LinkedReportPath.LastIndexOf('/')).TrimEnd('/'); CheckLinkedFolderExists(rsService, trusteduserHeader, condition, conditions, linkedReportFolderPath); ReportingService2010.CatalogItem[] foundLinkedItems = null; condition.Values = new string[] { linkedReportName }; rsService.FindItems(trusteduserHeader , linkedReportFolderPath , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundLinkedItems); if (foundLinkedItems == null || (foundLinkedItems != null && foundLinkedItems.Count() == 0)) { rsService.CreateLinkedItem(trusteduserHeader , linkedReportName , linkedReportFolderPath , parentReportPath , LinkedReportProperties); } if (xLinkedReportParameters != null) { //// List of properties to copy from parent to linked reports. ??? //var requestedProperties = new ReportingService2010.Property[] { // new ReportingService2010.Property { Name = "PageHeight" }, // new ReportingService2010.Property { Name = "PageWidth" }, // new ReportingService2010.Property { Name = "TopMargin" }, // new ReportingService2010.Property { Name = "BottomMargin" }, // new ReportingService2010.Property { Name = "LeftMargin" }, // new ReportingService2010.Property { Name = "RightMargin" } //}; IEnumerable <XElement> linkedReportParams = xLinkedReportParameters.Descendants("Param"); if (linkedReportParams.Count() > 0) { List <ReportingService2010.ItemParameter> ItemParamsList = new List <ReportingService2010.ItemParameter>(); foreach (var linkedReportParam in linkedReportParams) { string defaultValues = linkedReportParam.Attribute("DefaultValues").Value; if (!string.IsNullOrEmpty(defaultValues)) { ReportingService2010.ItemParameter[] parentReportParams = null; rsService.GetItemParameters(trusteduserHeader , parentReportPath , null , false, null, null, out parentReportParams); bool paramExists = false; ReportingService2010.ItemParameter ip = new ReportingService2010.ItemParameter(); ip.Name = linkedReportParam.Attribute("Name").Value; foreach (var parentReportParam in parentReportParams) { if (parentReportParam.Name == ip.Name) { ip.AllowBlank = parentReportParam.AllowBlank; ip.MultiValue = parentReportParam.MultiValue; ip.Nullable = parentReportParam.Nullable; ip.Prompt = parentReportParam.Prompt; ip.PromptUser = parentReportParam.PromptUser; ip.PromptUserSpecified = parentReportParam.PromptUserSpecified; paramExists = true; break; } } if (paramExists) { ip.DefaultValues = defaultValues.Split(','); if (linkedReportParam.Attribute("Hide") != null && linkedReportParam.Attribute("Hide").Value.ToLower() == "true") { //hide the paramerter using combination of parameters. There is no Hide property which reflects UI Hide checkbox ip.PromptUser = false; ip.PromptUserSpecified = false; ip.Prompt = null; } ItemParamsList.Add(ip); } } } rsService.SetItemParameters(trusteduserHeader, LinkedReportPath, ItemParamsList.ToArray()); } } } catch (SoapException ex) { LogMessage("Not able to create linked report " + LinkedReportPath + " Error: " + ex.Message); throw; } break; } } } } }