how to add C# code in default.aspx in SharePoint - c#

I am using SharePiont Server 2007 Enterprise with Windows Server 2008 Enterprise. I am developing using VSTS 2008 + C# + .Net 3.5. I want to add some C# code to default.aspx (more details, adding some logics to Page_Load method of default.aspx) and its code behind file. But I did not find default.aspx and its code behind file on disk? Where are they and how to modify?
BTW: another solution is to create a default.aspx file and its related code behind file by myself? But in this situation how to borrow the existing content/UI from current default.aspx (I am satisfied with current content/UI of default.aspx)?
I am not sure which solution is better and easier in my requirement to add C# code to Page_Load. Any advice or guides?

What kind of functionality are you trying to add and is this a publishing page or part of a standard WSS site?
EDIT
Check out Andrew Connell's article on MSDN :-)
http://msdn.microsoft.com/en-us/library/bb986729.aspx

Just a thought. How about creating a UI-less web part and adding it to the page ?

Related

ASPX website HTML Edit

Good morning,
I have a website that I have to edit for a client, but the website is on a local web server that is designed in aspx. I am looking at all the files and when trying to change Form options I am unable to find the HTML code behind the runat=server
what i ultimately need to accomplish is to change the options in a dropdown menu that allows users to choose from.
I am sorry if i am unable to explain it in depth, my web programming is weak when dealing with this.
Once published, an asp.net site would compile the code behind into a dll, you cannot see the code, only the markup.
Solution is to edit your website in visual studio and republish.

Can people find and download the Code File linked to your aspx page?

So I imported this aspx page done by a former dev who worked for the company I'm in now. I found that the aspx page left by him doesn't have a codebehind file so I assumed this wasn't the source code. I can't find the source so I added a code file and try to work it out on my own. But my main concern is this: clients can't access the code behind, right? Is a manually added code file subject to the same protection?
The codebehind file is there as a place to put your server side code. However it's technically not necessary to have one since you can put the code in the aspx file using c# script tags. It's however recommended to put it in the codebehind file for better separation between markup and code.
It does not matter if you add it yourself or if Visual Studio adds it for you. It does not change anything in terms of access. In all events it executes on the server.
If your server is properly configured to run ASP.NET applications - which I believe it is - then IIS will not serve .cs files to a client. These will normally be accessible only through FTP. Try it yourself, by browsing to any .cs file in your application :)
Also notice that what you get when you browse to an .aspx file is not the very same code you'd see in Visual Studio, but the result of that being processed. IIS will serve the resulting HTML. So even if you have server side code in the ASPX file, that won't be visible to an end user browsing through your application.
Sounds like a web application project; in this case, the code is in the code-behind file as #TGH mentioned, and the code would be in the DLL compiled for the web application. Therefore, the only way to get that code is use a tool like Telerik JustDecompile, and decompile that DLL to grab the source code for EVERY file in the project. It would be much better to have the source, as these decompile tools do not include everything in that code-behind file.

Do we have to re-publish the Web-site if we modify a part of the code in the aspx pages?

If we make a slight modification of the code in the C# page or in the aspx page, do we have to republish the entire web-site after the modification?
I am using VS-2008 professional and the code is written in C#.
It depends, if you are connnected to the website using a ftp connection (Solution showing as ftp://ftp.somewebsite.com) then your alterations will be updated real time. If you are using a local copy of the website (offline website), you need to publish the entire website once your are done.
So to answer your question we need more information about how you setup your website in the solution.
There are two case of modification:
UI (HTML Code), you can just click to refresh the browser without having to rebuild the solution
Server Code (C# code), you have to click F6 in VS2008 and rebuild the solution
It depends on which code you modify:
if you make a change to the asp markup of the aspx , than you don't have to.
if you change your code behind, then you will need to rebuild your
project therefore you have to republish it.

What is the best way to add customized button and link it to C# code in sharepoint designer 2007

I am trying to create a customized button in sharepoint designer 2007. What is the best way to do this? Using toolbox? or create a web part? And how to link the button I created to a piece of C# code. I am quite new to the sharepoint development. Hope any one can help me.
You can't easily add c# code through designer. You'll need to create a web part. If you must add c# code in-line on the page you'll need to modify the web.config to allow in-line code. This isn't really recommended though. The best approach would be to create a web part. Also depends on what you want to do - could be solved in another way - html & javascript/jQuery?

Run a aspx page into a Sharepoint folder

I have a aspx page and I'd like to run it into a sharepoint folder. Is there a way to execute this page like a html page? What I really need is to run a c# code that is together the aspx page (code behind) to read a SQLite database and shows the result in a good interface (html-css-javascript).
Obs.: I have a assembly reference for the SQLite.
Thanks a lot!
You need to create an application page inside sharepoint and move your code in that application page. its very simple, please see this link.
http://www.c-sharpcorner.com/uploadfile/anavijai/how-to-create-custom-sharepoint-2010-application-page-using-visual-studio-2010/
Please note that application page only support web forms and not MVC
Not sure "run it into a sharepoint folder" means... You can't have page with code behind in regular SharePoint folders.
You can put ASPX pages (even with codebehind) in Layouts folder on server's disk and they will be avaiable with ....\layouts\your_page.aspx urls.

Categories