Using SPWebPartManager and Sharepoint WebParts in standard ASP.NET page - asp.net

I have a server with WSS 3.0 installed and a functional team site. But I want to build a series of pages on a seperate site that are standard asp.net 2.0 type pages but include web parts and will display some summary information and links back to the WSS site (like to the documents). The pages will be added to an existing site that will not be converted to a WSS site.
I have attempted to include the SPWebPartManager (and WebPartZones) to the page but am getting a "Object reference not set to an instance of an object." even though I have done the "Register Tagprefix="SharePoint" on the page and included the Microsoft.Shareoint reference in the project.
Does anyone know where I can get a minimal environment for a page to do this type of thing?
Thanks

you know asp.net has it's own web part manager. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartmanager.aspx
although what it sounds like to me you are trying to do is simply read documents from a sharepoint list. In which case you dont need sharepoint web parts you just need to call the sharepoint web services.

Related

I can't find options for Select Master Page or Place code in separate file in VS2012

I installed VS 2012 on my work PC, and for the life of me when I go to add a new web form, I cannot see or find the 2 options for Select Master Page or Place code in separate file.
Any ideas on how i can find them?
I've just been fooled by just that for the past hour. What I've found is that the 'old' method of using the menu option 'Add web page using master' (or similar) has vanished, and been replaced by 'Content Page'. When you select this, you're then given the option of choosing a master page.
Incidentally, I don't get the option of starting a web site project, which may be why I'm not seeing this either.
You should have web form with master page in the add items?
Placing code in separate file is a different concept called code-behind. You will have an ASPX file and a cs / vb file which handles the events.
e.g.
Default.aspx
Default.aspx.cs
EDIT: Based on comment.
You may be using a Web Site on your laptop, but a Web Application in work. See Web Application Projects v's Web Site Projects.
Take a look at ASP.NET Web Site or ASP.NET Web Application?, this might also help in deciding which to use. Generally, I always go for Web Application.
You can use VS to convert from a Web Site to a Web Application, but AFAIK, you can't do it the other way round unless you create a new project and copy across the relevant parts - which could be a big job depending on the size of the site.

Using AspCompat in a SharePoint web part page

I'm in the process of creating a SharePoint web part that needs to use a single-threaded COM component. I've discovered that in order to make this work well, I need to add the AspCompat="true" directive to the page where the web part will live. The problem is I can't seem to set up such a page.
I created a new blank web part page via the regular browser interface, then added AspCompat to it using SharePoint Designer. But that causes it to become un-ghosted and the SafeMode parser says that directive isn't allowed. I then modified the blank web part page template to include the directive and created a new page, but got the same error.
I basically need to set up a page within my SharePoint site that is stored in the file system, has that directive, and can contain my web part. How would I go about creating such a page?
I recently answered this question with some instructions that includes how to supply new site content page templates that you can use to host web parts. I think it's likely to work for you.
In your case, your aspx page template would have that AspCompat directive built-in.
According to Microsoft SharePoint developer support, it is simply not possible to use AspCompat within a SharePoint site. The SPPageParserFilter class, which is the one that disallows certain page directives, is apparently involved in processing all pages, even those that are on the file system. See this blog post for more details.

Sharepoint with ASP.Net Web Application

What I need to do is create a web application that can run inside SharePoint. It needs to be more involved then a web part and include many pages and a database. I know you can create a SharePoint application that goes under the Action bar, but I would like to create something that is run like how a site is. I would want a few tabs to show different sites, each running the same application, just showing their own data.
It looked like creating a site definition would be the best route to achieving this, but I have not been able to get it to become like an ASP.Net Web Application. Anyone know of any other project type or method that can be done to develop an ASP.Net Web Application that simply shows up in SharePoint? I know I can do it in a page viewer webpart, but that just seems like a cheap hack to create an IFrame and not the optimal solution. I don't need any true integration with sharepoint, other then using it for Authentication and a display mechanism. Our corporate intranet is setup using SharePoint, so anything that I build has to exist within it.
If anyone has any guidance, I would love to hear your suggestions.
Thanks!
It's actually pretty straightforward, at the basic level:
Create your ASPX pages with codebehinds in your own assembly - just like normal.
Use the Sharepoint master pages (look at the existing ones to mimic their styles and markup)
Create a Feature which adds a link to your "entry point" page(s) to the SP menu
Deploy your assembly to the GAC

How to add custom ASP.NET pages into sharepoint

How to add custom ASP.NET pages into sharepoint?
I am very new to sharepoint but what I realized is that I can only make plain text pages or links. but what if I have a website already built in ASP.NET and want to add it through sharepoint.
Or is it possible to build the website itself from sharepoint including dynamic server side controls like buttons, trees ....
Simple answer: put your *.aspx files in inside the _layouts folder, usually located at
c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\
afterwards you can access you page (named page1.aspx for example) through the sharepoint site by:
http://your site name/_layouts/page1.aspx
You can have inline code and/or code-behind, just like in a normal aspx page.
However, please note that pages added through this method are called application pages, meaning that they cannot be customized (easily) by the user and are available under all site collections in your farm.
SharePoint supports another kind of pages, called Site Pages which are site-specific, you can read more about them here.
See these questions which should cover everything you need:
How would you convert an ASP.NET site to work as a SharePoint site?
Moving from custom ASP.NET application to Sharepoint Services
Deploying custom Asp.net applications to same IIS site as Sharepoint
SharePoint - ASP.Net Controls Integration
Sharepoint controls in ASP.NET application
Also this page on SharePoint Dev Wiki.
This Visual How To walks you through the process of creating an application page step by step.
Creating an Application Page in Windows SharePoint Services 3.0
http://msdn.microsoft.com/en-ca/library/bb418732.aspx
The presenter of the video, Ted Pattison, has a book that is a great resource to help you get up and started with SharePoint development.
Inside Windows SharePoint Services 3.0
http://www.amazon.com/dp/0735623201?tag=g6consulswebs-20
If you want some .aspx-Pages in a SharePoint-Website, you can build a SharePoint-Module Feature containing the .aspx-Pages.
See How to: Provision a File and Create and Use a SharePoint Feature Package

Displaying the current authenticated Sharepoint user from an asp.net Page Viewer Web Part

I am creating a standalone asp.net page that needs to be embedded into a sharepoint site using the Page Viewer Web Part. The asp.net page is published to the same server on a different port, giving me the URL to embed.
The requirement is that after a user is authenticated using Sharepoint authentication, they navigate to a page containing the asp.net web part for more options.
What I need to do from this asp.net page is query Sharepoint for the currently authenticated username, then display this on the page from the asp.net code.
This all works fine when I debug the application from VS, but when published and displayed though Sharepoint, I always get NULL as the user.
Any suggestions on the best way to get this to work would be much appreciated.
If you want to retrieve the currently authenticated user from the SharePoint context, you need to remain within the SharePoint context. This means hosting your custom web application within SharePoint (see http://msdn.microsoft.com/en-us/library/cc297200.aspx). Then from your custom application reference Microsoft.SharePoint and use the SPContext object to retrieve the user name. For example:
SPContext.Current.Web.CurrentUser.LoginName
You can still use the Page Viewer Web Part to reference the URL of the site, now located within the SharePoint context.
Thanks heaps for the answers!
Turns out that as long as the asp.net page is using the same URL and port as the Sharepoint site, authentication works across both sites.
The solution is to use a Virtual Directory inside of the sharepoint site and install the asp.net page there.
When it works in debug, is that being used in SharePoint?
Your page and the Sharepoint site might as well be on different servers as far as authentication is concerned -- in order to get the information over you might need to pass it via the QueryString from the webpart if you can -- or you might need to make your own webpart to do this (just put an IFRAME in the part with the src set to your page with the QueryString passing the username).
It does seem that this would be a security issue if you use the name for anything though -- if you are just displaying it, then it's probably fine.
If you actually need to be authenticated, you might need to add authentication into the web.config of the site hosting your standalone page.
edit: I think you'd have better luck putting your page on the same port and server as SharePoint.
I suspect you will have a hard time specifically querying SharePoint for the currently authenticated username. I can't think of a way to easily access the SharePoint context from a separate web application like you are describing.
I don't know what kind of authentication scheme you are using, but you may want to consider using Kerberos, as I've found that it can make these kinds of scenarios a little easier by allowing for delegation and passing credentials from application to application or server to server.

Resources