Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to add a page from a web app to a Sharepoint site

2 views
Skip to first unread message

milop

unread,
Dec 14, 2009, 1:36:35 PM12/14/09
to
Hello.

I have an existing web app with one ASPX page. This page writes PDF's to the
browser. Here's sample code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try
Dim attID As String =
Server.UrlDecode(Request.QueryString("id"))
attID = attID.Replace(CChar(" "), "+")
Dim att() As Byte = _myBusinessClass.GetAttachment(attID)
Response.ContentType = "application/pdf"
Response.BinaryWrite(att)

Catch ex As Exception
Response.Write("Error displaying the attachment. </br><br/>" &
ex.ToString())
End Try
End Sub

That's it. How do I get this on the Sharepoint 2007 (MOSS) server so that
it's accessible to all sites?

I put the .aspx page in the _layout directory and I signed the .dll and put
it into the GAC, but I receive the general Sharepoint Error page.

Thanks in advance,

Mike


Message has been deleted

jee266

unread,
Dec 16, 2009, 8:46:24 PM12/16/09
to

Have you put the full asembly name in the inherit attribute of the
page?

NB: You can get the real error and stack trace by doing as teach on
this blog
http://www.andrewconnell.com/blog/archive/2007/02/01/5935.aspx.

And in my opinion, you should code an httphandler instead of a page
who respond to a specific relative URL instead of having to pass
through the page lifecycle (extra code that run and that is not used
in this case). Than you could make it available by the sharepoint
SPWebConfigModification class via a "WebApplication scoped feature"
or
"farm scoped feature" (in a feature receiver).

If you don't know how to implement this just let me know and i'll
give
you more detailed information.

milop

unread,
Dec 17, 2009, 6:20:47 AM12/17/09
to
Hello Jee. Thanks for the response.

That's a good point, I will check the assembly name in the aspx page. I'm
using VB.Net and removed the namespace from the project properties. Maybe
that has something to do with it.

That's the second time I heard someone mention an httphandler. If you can,
could you provide me with more information?

Thanks again,

Mike

"jee266" <jeanphil...@hotmail.com> wrote in message
news:c0d41d48-3de9-4fb5...@f20g2000vbl.googlegroups.com...

Have you put the full asembly name in the inherit attribute of the
page?

NB: You can get the real error and stack trace by enabling asp.net
page trace in web.config file, than after execution of your page, you
only have to browse to "Trace.axd" at the root of your site and than
click on your page to see the error. Just put <trace enabled ="true"
requestLimit ="20" writeToDiagnosticsTrace ="true " pageOutput ="true"/
> (under <system.web> node to enable trace.

Message has been deleted

jee266

unread,
Dec 18, 2009, 10:06:19 PM12/18/09
to
On 17 déc, 06:20, "milop" <mi...@slomins.com> wrote:
> Hello Jee. Thanks for the response.
>
> That's a good point, I will check the assembly name in the aspx page. I'm
> using VB.Net and removed the namespace from the project properties. Maybe
> that has something to do with it.
>
> That's the second time I heard someone mention an httphandler. If you can,
> could you provide me with more information?
>
> Thanks again,
>
> Mike
>
> "jee266" <jeanphilippebe...@hotmail.com> wrote in message
> you more detailed information.- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

Ok look. An HttpHandler is a class that can, by a simply adding a
node
to a Web.Config that point to that class, catch an HTTP request and
run custom code. This class have to implement
a specific interface System.Web.IHttpHandler (to run a piece of code
synchronously) or System.Web.IAsyncHttpHandler (to run custom code
asynchronously). The latest is a little bit more complicated but can
be really useful in a context where you have a relatively long
operation to do and you dont want to prevent other request to the
worker process to wait until its done to continue their work.

Here is a prototype of an IHttpHandler class.


'You need a reference to System.Web .Net assembly in your Class
library
Imports System.Web


Public Class PDFWriter
Implements IHttpHandler


Public ReadOnly Property IsReusable As Boolean Implements
System.Web.IHttpHandler.IsReusable
Get
Return False
End Get
End Property


Public Sub ProcessRequest(ByVal context As
System.Web.HttpContext)
Implements System.Web.IHttpHandler.ProcessRequest
''Use context to write your PDF file here
Try
'You can get information from context.Request just as in
a
webpage
'Then add header and write your binary file here
'by using context.Response
Catch ex As Exception
'redirect to an error page
'this is a better practice cause writing HTML here can
cause ContentType Issue with some browsers.
End Try


End Sub
End Class
'End


Here is the web.config modification that need to be done to make the
handler accessible via an URL


Locate the <Handlers> node under <system.webServer>


Add a child node format as this one to the <Handlers> node


NB: You should put this one as the last child of the handlers node.


<add name="UniqueNameForHandler" verb="*" path="RelativeUrlToHandle"
type="FullyQualifiedClassName, FullyQualifiedAssemblyName, Version=X.
0.0.0, Culture=neutral, PublicKeyToken=[Token]" />


Name attribute is a unique name that you must provide for your
handler.
Verb is the http method to wich you want your handler to respond. EX:
GET,POST,... If you use the * wildcard, it will catch the request for
any of theses.
path is the relative URL to wich you want your Handler to respond.
Type is the full typename of your handler class.


It should look like this one.


<add name="ReportViewerWebControl" verb="*"
path="Reserved.ReportViewerWebControl.axd"
type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />


Thats it!


If you need to debug, just attach to the w3wp.exe process.


Hope this will help you...


0 new messages