There is an OnInit event that fires each time the report is run. The method can be used in custom code like this,
Protected Overrides Sub OnInit()
' do something
End Sub
Ian|||Thank you Ian. I appreciate your response. Is there some way once I use this code that I can make it fire a url?|||You could do something like this:
Protected Overrides Sub OnInit()
Response.Redirect("MyOtherUrl.aspx")
End Sub|||Thank you so much! That sounds like exactly what I was looking for!|||I tried this and it says Name Response is not declared. Was I supposed to use it in the code window?|||Response.Redirect will not work since the code is not executed directly within the context of the page.
What you will need to do is use the WebRequest class, see example below. Also, you will need to add a reference to System.Net, using the Reference tab on the Report Properties dialog.
Protected Overrides Sub OnInit()
Dim request As WebRequest = WebRequest.Create("http://www.example.com")
Dim response As WebResponse = request.GetResponse()
End Sub
Ian|||Do I have to create a custom assembly or can I use the code in the code window? I do not know what to enter on the references tab. Thank you so very much for your patience.|||Yes, you can use the Code section in the in the Report properties window.
Actually, I was mistaken. You do not need to add any thing in the References Tab. The Classes you need are in the System.Net namespace and are contained in System.dll.
Since this is the case, all you will need to so is add the namespace to the beginning of all the WebRequest and WebResponse class names, something like,
Protected Overrides Sub OnInit()
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create("http://www.example.com")
Dim response As System.Net.WebResponse = request.GetResponse()
End Sub
Ian|||I tried this but got an error. "An error occurred while executing OnInit: The remote server returned an error: (401) Unauthorized.|||This means that the server you are trying to hit is not allowing anonymous access. Take a look at the link below on how to supply user credentials.
http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.credentials.aspx
Ian|||
I tried the exact same thing
Protected Overrides Sub OnInit()
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create("http://www.example.com")
Dim response As System.Net.WebResponse = request.GetResponse()
End Sub
And that did not work, So I tried putting a msgbox in the routine and the msgbox did not pop up. So i am not sure why the routine is not getting called
?
|||The routine is probably getting called, but is not doing anything visibly--just silently hitting a web site. And, the message box may not appear since the context the code is executing is not graphical.Try this, place a Textbox on the report with the expression "=Code.GetLength()", and place the following in the Code section. You should see the length of the response in the Textbox.
Private m_length as Integer
Protected Overrides Sub OnInit()
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create("http://www.example.com")
Dim response As System.Net.WebResponse = request.GetResponse()
m_length = response.ContentLength
End Sub
Function GetLength() As Integer
Return m_length
End Function
Ian|||We could not get this to work correctly (Redirect w/ getting the user credentials). Could you show me a sample with both being done?|||
I still cannot get it to work. I do see the report trying to do something but not actually redirecting the entire page. Are there any permissions I need to set to allow such actions for a anonymous user?
Thanks.
No comments:
Post a Comment