SharePoint Developer Center >
SharePoint Products and Technologies Forums
>
SharePoint - Development and Programming
>
code-behind in sharepoint
code-behind in sharepoint
- does sharepoint support 'normal' aspx file with .cs file as code behind? if yes, what should i do? for example , create the aspx first with spd? where should i put the cs file?thx in advance!Andree
Answers
- Yes , read the following article for step by step details on how to achieve this.Adding Code-Behind Files to Master Pages and Page Layouts in SharePoint Server 2007http://msdn.microsoft.com/en-us/library/bb986729.aspx
http://razi.spaces.live.com/- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Hi Andree,
You can refer this link to write both inline or code-behind code -
http://avinashkt.blogspot.com/2009/06/how-to-write-server-side-c-code-in.html
Regards, Avinash | avinashkt.blogspot.com- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Please take note that enabling inline code by using "PageParserPath" is discouraged by Microsoft , please read the support details section at http://msdn.microsoft.com/en-us/library/bb862025.aspx. Inline code is usually targeted to very specific situations so in case your take that route you need to be aware of security ramifications it brings.
http://razi.spaces.live.com/- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Hi Andree,
Regarding ASPX files... you can refer default.aspx (by-default home page) page via SharePoint Designer to create and maintain ASPX files.
Regarding code-behind files... you can refer second approach mentioned in earlier posted link. You can maintain a class library project that will contains all your code-behind files.
If you want to have same navigation bar... then you have to convert your aspx pages into content pages (like default.aspx).
While converting... you can copy all your existing aspx page's body content in PlaceHolderMain content place holder in newly created content page.
Regards, Avinash | avinashkt.blogspot.com- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Perhaps you may want to start with what is known as "Minimal Master Page" , visit http://msdn.microsoft.com/en-us/library/aa660698.aspx.for more details on MOSS 2007. In case you have WSS 3.0 you can get some info on minimal master page of WSS 3.0 at http://social.msdn.microsoft.com/forums/en-US/sharepointcustomization/thread/aea7cb96-a2a7-439e-8007-4ea05b00f6c4Once this base is ready , you can start moving your code into the master page (with code behind , as mentioned in previous post) , some of the stuff will integrate directly and some stuff might need some effort , really depends on complexity of your existing pages.
http://razi.spaces.live.com/- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Partial classes is a feature of C# to make it possible to split the definition of a class or a struct , or an interface over two or more source files. C# compiler will combine the definitions together.
Partial Class Definitions (http://msdn.microsoft.com/en-us/library/wa80x488%28VS.80%29.aspx)
public partial class addproject : System.Web.UI.Page
This line usually means that you have a *.aspx page which is a class named addproject and you have a separate file *.aspx.cs, this is the code-behind file which can also use the objects defined in *.asppx page.
You can reference the following article for detailed explanation:
ASP.NET Page Class Overview(http://msdn.microsoft.com/en-us/library/ms178138.aspx)
If you don't want to use partial classes, you can reference the following articles for explicit reference of assembly:
Chapter 2: SharePoint Architecture (Part 2 of 2)(http://msdn.microsoft.com/en-us/library/bb892187.aspx)
Keep It Simple and Stupid.- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
All Replies
- Hi Lude8880,
You can create aspx file with .cs file as code behind by creating application pages which resides under "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Layouts".
Example: http://msdn.microsoft.com/en-us/library/bb418732.aspx
After then deploy it under the \12\Template\Layouts folder using a sharepoint Feature. You have to use Visual studio 2005/2008 not very sure abt SPD!!!
I hope that helps you.
- Yes , read the following article for step by step details on how to achieve this.Adding Code-Behind Files to Master Pages and Page Layouts in SharePoint Server 2007http://msdn.microsoft.com/en-us/library/bb986729.aspx
http://razi.spaces.live.com/- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Hi Andree,
You can refer this link to write both inline or code-behind code -
http://avinashkt.blogspot.com/2009/06/how-to-write-server-side-c-code-in.html
Regards, Avinash | avinashkt.blogspot.com- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Please take note that enabling inline code by using "PageParserPath" is discouraged by Microsoft , please read the support details section at http://msdn.microsoft.com/en-us/library/bb862025.aspx. Inline code is usually targeted to very specific situations so in case your take that route you need to be aware of security ramifications it brings.
http://razi.spaces.live.com/- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- thx guys, i have several asp.net files with codebehind, i just want them to be embedded in the sharepoint masterfile so they can share the sharepoint navigations bar, so its reverse engeneering, any good ideas?thxAndree
- Hi Andree,
Regarding ASPX files... you can refer default.aspx (by-default home page) page via SharePoint Designer to create and maintain ASPX files.
Regarding code-behind files... you can refer second approach mentioned in earlier posted link. You can maintain a class library project that will contains all your code-behind files.
If you want to have same navigation bar... then you have to convert your aspx pages into content pages (like default.aspx).
While converting... you can copy all your existing aspx page's body content in PlaceHolderMain content place holder in newly created content page.
Regards, Avinash | avinashkt.blogspot.com- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- Perhaps you may want to start with what is known as "Minimal Master Page" , visit http://msdn.microsoft.com/en-us/library/aa660698.aspx.for more details on MOSS 2007. In case you have WSS 3.0 you can get some info on minimal master page of WSS 3.0 at http://social.msdn.microsoft.com/forums/en-US/sharepointcustomization/thread/aea7cb96-a2a7-439e-8007-4ea05b00f6c4Once this base is ready , you can start moving your code into the master page (with code behind , as mentioned in previous post) , some of the stuff will integrate directly and some stuff might need some effort , really depends on complexity of your existing pages.
http://razi.spaces.live.com/- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- hi guys,i am a little wired...my cs file is a partial class(i think in tend to access the controls). i coudnt find any solution for patial classes.thxAndreepublic partial class addproject : System.Web.UI.Page
- Partial classes is a feature of C# to make it possible to split the definition of a class or a struct , or an interface over two or more source files. C# compiler will combine the definitions together.
Partial Class Definitions (http://msdn.microsoft.com/en-us/library/wa80x488%28VS.80%29.aspx)
public partial class addproject : System.Web.UI.Page
This line usually means that you have a *.aspx page which is a class named addproject and you have a separate file *.aspx.cs, this is the code-behind file which can also use the objects defined in *.asppx page.
You can reference the following article for detailed explanation:
ASP.NET Page Class Overview(http://msdn.microsoft.com/en-us/library/ms178138.aspx)
If you don't want to use partial classes, you can reference the following articles for explicit reference of assembly:
Chapter 2: SharePoint Architecture (Part 2 of 2)(http://msdn.microsoft.com/en-us/library/bb892187.aspx)
Keep It Simple and Stupid.- Marked As Answer bylude8880 Thursday, November 05, 2009 7:12 AM
- thx guys, idecided to make a external link , its easier and not so sophiscated.
- r there any new features by vs 2010 referrs to this problem? thx Andree
- Proposed As Answer byRazi bin RaisMVPThursday, November 05, 2009 5:40 AM
- Unproposed As Answer byCharlie WuModeratorThursday, November 05, 2009 6:45 AM
- Wait & see
Keep It Simple and Stupid. - Following are the links to forums decidated to Visual Studio 2010 and SharePoint 2010.You can post your query there for more details.SharePoint 2010 Product & TechnolgoiesVisual Studio 2010 Beta 2 (and related forums)PS: I accidently marked you previous post as an answer , please un mark it.
http://razi.spaces.live.com/


