Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Just a question:

What is the best way to interact with SharePoint with code? Trying to figure out the right area pursuing without wasting time. C#? JavaScript?

Right now I'm just trying to make a web part that is SharePoint List Driven...it will basically create a navigation bar and the names/links across that navigation bar would be displayed on however I have my SharePoint List configured.

share|improve this question
    
You can use either - whatever suits better to your case. Since there is not criteria what is "better" for you this question can't be answered as it stands now. –  Alexei Levenkov Jul 31 '13 at 1:57

3 Answers 3

up vote 1 down vote accepted

You can use C# for your webpart feature. Make an empty project, then add a webpart (non visual webpart) to the project. Use the C# object model to query the SPList object, then do a foreach loop to spit out the values into your nav bar.

The pain with C# comes when you have to update your feature with a different version number for the solution. That is unless you are excellent with the feature upgrade process. The pervious version webpart instance is stuck in WP zones of whatever ASPX they are stored in. I keep my solutions at version 1.0, then note a version number of the build in the feature description, which shows up in the features list in Site Settings.

You can use JavaScript for your web part feature. Make an empty project, then add a webpart (non visual webpart) to the project. Call the web service for getitems on the specific nav list. Visual studio will create a strongly named class for the SP site that the list lives in, that stores the definition of all the lists in that site. If your nav list changes, refresh the web serivce and update this strongly named class.

When your web part runs, the web service will run as the user that is logged in. So either make sure all visitors have view rights, or make a AD service account to call the web service. Once your Javascript returns the XML, use a parcer like Lync to XML to get the data and spit out the HTML into the nav bar.

It's more about comfortable preference than which is better. If you're using SharePoint 2013, make a SP app instead of a farm feature. Then you can only use JavaScript and web services.

share|improve this answer
1  
Good info. Thanks! –  mwilson Jul 31 '13 at 2:09

You can the lists.asmx webservice and javascript, bellow is the code taht I use to query SharePoint lists.

var url = document.URL;
if(url.indexOf("https://") != -1)
{
    var urllink = document.location.href.replace("https://","");
    var prefix = "https://";
}
else
{
    var urllink = document.location.href.replace("http://","");
    var prefix = "http://";
}   
var link = (urllink.split("/"))[0];

$(document).ready(function() {
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>Web Pages</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Title' /> \
                       </ViewFields> \
                    </viewFields> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: prefix+link+"/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});

var names = new Array();
var href = new Array();
var iterator;

function processResult(xData, status) {
    $(xData.responseXML).find("z\\:row, row").each(function() {

    names.push($(this).attr('ows_Title'));
    href.push($(this).attr('ows_FileRef'));

    });
}
share|improve this answer

I don't have access to the backend of Sharepoint (IT restriction) so I'm only autorized to use JavaScript for this kind of tasks, and it works great with the Sharepoint Web Services.

I've created a JavaScript API that is, I think, very useful and easy to use: SharepointPlus

Otherwise there are some alternatives like the popular SPServices.

So I'd say it depends of your needs, restrictions, skills and of the complexity of what you're trying to do at the end.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.