我有一个页面显示我所有的水晶报告,如下所示:
这些报告中有一个(可悲的是,硬编码的)url 公式,指向例如https://myserver.bla.bla
我想以某种方式以编程方式查找 url 的实例,并将它们更改为其他内容(有数百个这样的报告,现在没有足够的时间进入并更改所有链接)。
我一直在 FieldObjects 中四处寻找,但似乎无法弄清楚如何更改它们的格式公式。当我查看 reportdocument.fieldformulas 时,不存在 url 格式公式。
公共部分类报告:System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
iLogger logger = LoggingFactory.CreateLogger();
ReportDocument rd = new ReportDocument();
string fileName = Request.QueryString["reportfile"];
if(!Regex.IsMatch(fileName,@"^[ 0-9a-zA-Z-_\\]+.rpt$"))
{
ArgumentException aex = new ArgumentException("Invalid file/path specified.");
logger.LogError(ActionTypes.Administration, HttpContext.Current.User.Identity.Name,
"Passed invalid file path to report viewer: " + fileName, aex);
throw aex;
}
if(Path.IsPathRooted(fileName))
{
ArgumentException aex = new ArgumentException("Absolute path passed to report viewer.");
logger.LogError(ActionTypes.Administration, HttpContext.Current.User.Identity.Name,
"Passed invalid file path to report viewer: " + fileName, aex);
throw aex;
}
string rootPath = Server.MapPath("~/Reports/");
string path = Path.Combine(rootPath, fileName);
if (File.Exists(path))
{
rd.Load(path);
}
//get all keys starting with Prompt
var prompts = Request.QueryString.AllKeys.Where(q => q.StartsWith("Prompt"));
foreach (string promptKey in prompts)
{
//try to convert the rest of the string to an int
//yes, this should probably not just be a replace here...
string withoutPrompt = promptKey.Replace("Prompt", "");
int promptVal;
if (int.TryParse(withoutPrompt, out promptVal))
{
rd.SetParameterValue(promptVal, Request.QueryString[promptKey]);
}
//rd.SetParameterValue(promptKey, Request.QueryString[promptKey]);
CrystalReportViewer1.ReportSource = rd;
}
}