- Using Visual Studio, create a new web site project on the folder created in the previous step.

- Add a Web Form (aspx page) to the folder:
- Add some content to the page (eg "Hello World") and save the page
- Verify that the page can be browsed using the SharePoint URL plus the new folder and name:
Adding SharePoint to our project
So far we have an ASPX page running on the SharePoint server, we now need to connect to the SharePoint system.
- Open the Code Behind (.cs) file and add "Using Microsoft.Sharepoint"
- This will cause an error (red line) initially as we need to add the reference to the SharePoint DLL on the server.
- Add a reference to your project: Right click the project in the solution tree, and select "Add Reference", choose the "Browse" option and browse to the SharePoint DLL on the SharePoint server.
The Sharepoint DLL will be in c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI (note \15\ is for Sharepoint 2013, use \14\ for SP 2010 etc)
- Select "Microsoft.Sharepoint.dll" and click "Add" to add the reference
- This will add several DLLs to the projects "Bin" folder and should clear the error on "Using Microsoft.Sharepoint" (after a pause)
NB This only needs to be done once for the project, you don’t need to repeat this for every page.
Testing the SharePoint link
Insert the URL of your Sharepoint site in the new SPSite function.
This code accesses the SharePoint site (the root site, but it doesn’t matter which site, as long as it is a valid site on your SharePoint installation.
Next it open the SPWeb object associated with this site and gets the current user from the web object.
The name of the current user is output to the literal.
- Save the page and browse to (or refresh) the page:
This demonstrates connection to the SharePoint system.








No comments:
Post a Comment