none
How can i use sharepoint class in asp.net web application

    Question

  • Hi.

    I have a file search application which I made with asp.net.

    And I must modify this application use the sharepoint search engine

    i wanted know if i can use sharepoint class in Asp.net project

    New Project -> ASP.net WEB application -> add web form.aspx -> write source aspx.cs file(SPSite site = new SPSite("http://myserverpc23:2222/");) -> build

    errors submit is can`t find http://myserverpc23:2222/ (sorry i use Japaness version so i don`t know english error message)

    http://myserverpc23:2222/ is Sharepoint Site

    I can Access http://myserverpc23:2222/ And No problem if i tried SPSite site = new SPSite("http://myserverpc23:2222/"); in Sharepoint Web part project .

    It is an error if I use the SPSite in ASP.net project.

    please teach to me

    Saturday, September 07, 2013 4:05 AM

Answers

  • SharePoint Classes which are a part of Microsoft.SharePoint.dll can only be used from a machine which has sharepoint installed.

    if you try to copy this DLL and then try to use SPWeb, or SPSite ... you will only get errors.

    If you want to use the SharePoint Search Engine from your ASP.NET app, you should use SharePoint Client Object Model API. 

    Microsoft.SharePoint.Client.Runtime.dll and Microsoft.SharePoint.Client.dll

    here is documentation which helps you client APIs to program against Search

    http://msdn.microsoft.com/en-us/library/sharepoint/dn423226.aspx


    val it: unit=()

    • Proposed as answer by RoyJoyson Saturday, September 07, 2013 6:25 AM
    • Marked as answer by Gs.NangChun Monday, September 09, 2013 6:16 AM
    Saturday, September 07, 2013 5:48 AM
  • Hi NangChun,

    Hope you get enough info from the url shared by MSDN Student. Also you can refer the sample code from the same url

    using (ClientContext clientContext = new ClientContext("http://<serverName>/sites/<siteCollectionPath>"))
    {
        KeywordQuery keywordQuery = new KeywordQuery(clientContext);
        keywordQuery.QueryText = "SharePoint";
        SearchExecutor searchExecutor = new SearchExecutor(clientContext);
        ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
        clientContext.ExecuteQuery();
    }

    Regards  Roy Joyson
    Please remember to mark your question as "answered"/"Vote helpful" if this solves/helps your problem.


    Roy Joyson

    • Marked as answer by Gs.NangChun Monday, September 09, 2013 2:08 AM
    Saturday, September 07, 2013 6:27 AM

All replies

  • SharePoint Classes which are a part of Microsoft.SharePoint.dll can only be used from a machine which has sharepoint installed.

    if you try to copy this DLL and then try to use SPWeb, or SPSite ... you will only get errors.

    If you want to use the SharePoint Search Engine from your ASP.NET app, you should use SharePoint Client Object Model API. 

    Microsoft.SharePoint.Client.Runtime.dll and Microsoft.SharePoint.Client.dll

    here is documentation which helps you client APIs to program against Search

    http://msdn.microsoft.com/en-us/library/sharepoint/dn423226.aspx


    val it: unit=()

    • Proposed as answer by RoyJoyson Saturday, September 07, 2013 6:25 AM
    • Marked as answer by Gs.NangChun Monday, September 09, 2013 6:16 AM
    Saturday, September 07, 2013 5:48 AM
  • Hi NangChun,

    Hope you get enough info from the url shared by MSDN Student. Also you can refer the sample code from the same url

    using (ClientContext clientContext = new ClientContext("http://<serverName>/sites/<siteCollectionPath>"))
    {
        KeywordQuery keywordQuery = new KeywordQuery(clientContext);
        keywordQuery.QueryText = "SharePoint";
        SearchExecutor searchExecutor = new SearchExecutor(clientContext);
        ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
        clientContext.ExecuteQuery();
    }

    Regards  Roy Joyson
    Please remember to mark your question as "answered"/"Vote helpful" if this solves/helps your problem.


    Roy Joyson

    • Marked as answer by Gs.NangChun Monday, September 09, 2013 2:08 AM
    Saturday, September 07, 2013 6:27 AM
  • You can use SPSite if (assume you use SharePoint 2013): 

    1. Your ASPNET site in server part of farm machine.
    2. Your .NET 64 bit.
    3. You reference same Share Point version of your farm.
    4. Your site work with framework 4.0

    If you use code from server is not part of farm use  the SharePoint 2013 search Query APIs:
    http://msdn.microsoft.com/en-us/library/sharepoint/dn423226.aspx

    Tarek Yehia
    Blog:http://sharepointserver-2007.blogspot.com/


    Tarek Yehia

    Saturday, September 07, 2013 6:31 AM