none
How to use C# code in Sharepoint

    Question

  • How to use C# code in sharepoint ..!!?

    do i have to open web site in VS to develeope custom code...!?

    i have tried but VS is not allowing me to do this...

    any help would be appreciated.

    Thanks

    Parth

    Monday, October 20, 2008 1:16 PM

Answers

All replies

  • Hello,
    how do you want to use it? Give us an example

    You can use C# to program Sharepoint in several ways, here are some examples:
    - You can write C# code in .aspx pages using SharePoint Designer (SPD)
    - You can write C# code for .aspx code behind using Visual Studio and edit the pages with SPD to use the code behind
    - You can write web parts in C# using Visual Studio and deploy them to the SharePoint site.

    /WW

    http://www.wictorwilen.se/
    Monday, October 20, 2008 1:19 PM
  • You cannot open a SharePoint site directly in Visual Studio. Use VS to create server controls, webparts, workflow projects, page classes etc etc. You can then use these in SharePoint, but the exact procedure depends on what you want to do. Deployment is different depending on what custom components you are creating, and depending on your requirements there may not be a need to use VS at all

    Stu
    http://www.starznet.co.uk/sharepoint/blog Please mark replies as answered if they have helped answer your question
    Monday, October 20, 2008 1:22 PM
  •  Hi,
    I am creating it on Newform.aspx where some of my TextBoxes are there which will display my details such as names and some dropdown data of other lists with depending selection of the dropdown other data in textbox with related lists so for that i need to add several Buttonclicks and selectedIndexChnage Events on Sharepoints NewForm.aspx page

    I have no clue how do i do it..!?

    Parth
    Monday, October 20, 2008 1:33 PM
  • Hello,
    you can either writing inline code using SharePoint Designer and <% %> statements, or you can put the code in a custom code DLL by inheriting from Microsoft.SharePoint.WebPartPages.WebPartPage and change the the newform.aspx file to inherit from that aspx page instead using SPD.
    /WW
    http://www.wictorwilen.se/
    Monday, October 20, 2008 1:42 PM
  • I would like to do the same thing as Parth, but the instructions on how to write code for Sharepoint pages is not documented very clearly in any source. I think what would help people in our situation is a clear method on how to develop under MOSS. As a VS2005 coder, I am comfortable with aspx using code behind, but how this translates to Sharepoint is frustratingly complicated.

    I read so many walkthroughs and explanations about creating web parts and publishing them to MOSS, but none of them are very articulate. Can anyone provide a link to a simple step-by-step guide for simply writing code in VS for MOSS? I think this would help folks like Parth and I who want to start developing simple pages in SP using Visual Studio.

    Thanks!!!

    Monday, October 20, 2008 2:51 PM
  • Wictor,

    Correct me if I'm wrong, but you can't use server side code (<% %>) in SharePoint Designer unless you turn off the "security checker" that keeps Power users from running potentially dangerous API calls (such as RunWithEvelavedPermissions) without approval from the SharePoint admins.

    Thanks,
    Eli


    Eli Van Eenwyk
    Monday, October 20, 2008 3:14 PM
  • Hello,
    yes you need to lighten up the security if you would like to write code. I quickly wrote a small Hello World sample on how to create a small application in SharePoint using some C# code, asp.net controls and scripts blocks, check it out here: http://www.wictorwilen.se/Post/The-simplest-form-of-SharePoint-application.aspx

    /WW
    http://www.wictorwilen.se/
    • Marked as answer by Parth Rawal Wednesday, October 22, 2008 5:32 AM
    Monday, October 20, 2008 4:40 PM
  • Wictor-

    Thanks for your helpful example. Can you elaborate on your last statement?

    If you want your code placed in a code behind file, just inherit from the Microsoft.SharePoint.WebPartPages.WebPartPage class and create your own code behind.


    What does the syntax of that look like?
    Monday, October 20, 2008 5:36 PM
  • Hi actually i want to know that before writing code in my aspx page do i have to check out from page and afer updating do i need to check in again,

    Please can you give step by step procedure to writing and deploying that page

    Parth
    Tuesday, October 21, 2008 4:49 AM
  • Hello again,
    to close the bag I decided to show how you create a code behind assembly for the previous sample. Here ya go: http://www.wictorwilen.se/Post/The-simplest-form-of-SharePoint-application-part-2.aspx

    /WW
    http://www.wictorwilen.se/
    • Marked as answer by Parth Rawal Wednesday, October 22, 2008 5:32 AM
    Tuesday, October 21, 2008 6:22 AM
  • Hi
    i am being  adding the feature using following link:

    http://geekswithblogs.net/evgenyblog/archive/2008/01/27/118966.aspx

    i have completed till deploying but the feature is not coming for the Activation

    what i am missing?
    • Marked as answer by Parth Rawal Wednesday, October 22, 2008 5:32 AM
    Tuesday, October 21, 2008 8:08 AM
  • Wictor-

    I can't thank you enough for you examples. I'm going to try them out right now. Can I assume that using this method, I will be able to access the Sharepoint object model (microsoft.sharpeoint.dll) in my code behind?

    Again, thanks A LOT. This straightforward example is just what I was looking for to get started coding in SP.

    MGoulet
    Amherst, MA
    Tuesday, October 21, 2008 1:47 PM
  • Yup, you can access all of the SharePoint object model from your code behind.
    Just make sure that you read what Martin Hatch is writing in this thread, use my second sample (the first one was just to show you that it can be done).
    /WW
    http://www.wictorwilen.se/
    Tuesday, October 21, 2008 1:52 PM
  • Man, this works great! I went through your example step by step and it works perfectly, and gave me a lot of insight into how it is constructed. I'm close to getting a development environment that works for me now.

    I understand that enabling debugging is a real headache when using this method, but I guess nothing is easy at first. Will it be possible to communicate with other web parts on the page? For example, if I wanted to write a custom filter and send the results to a data view object that lives on the content page. Is this possible using this method?

    Again, thanks a ton.

    M
    Tuesday, October 21, 2008 2:55 PM
  • Hello,
    you can use the debugger (remote also) and attach to the w3wp process to debug.
    /WW
    http://www.wictorwilen.se/
    Tuesday, October 21, 2008 2:58 PM