Sharepoint 2010 Client Object Module getting a site url list - sharepoint

I’m trying to learn SharePoint Client Object Model, specifically how to get a list of all SharePoint site URLs using a remote connection. This is possible using webservices…but I want to do it using the client object model.
I’ve figured how to get the title lists of a specific sharepoint site using the following code:
client object module):
ClientContext ctx = new ClientContext( server );
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = WindowsAuthenticationCredentials(username, password);
Web w = ctx.Web;
var lists = ctx.LoadQuery(w.Lists);
ctx.ExecuteQuery();
//Enumerate the results.
foreach (List theList in lists)
{
}
Output:
Announcements, Master Collection Pages… etc…
How can I do the same to get a site url list?
In web services you can call the following to achieve that, but as I said just trying to figure out how to do the same using client object module. If you can provide c# code that would greatly be appreciated.
WSPSitedata.SiteData sitedata = new SiteData();
sitedata.Url = #SharePointBaseURL + #"_vti_bin/sitedata.asmx";
sitedata.Credentials = our_credentials
_sSiteMetadata metaData = new _sSiteMetadata();
_sWebWithTime[] webWithTime
sitedata.GetSite(out metaData, out webWithTime, out users, out groups, out vgroups);

The SharePoint Client Object Model CSOM is designed to remotly interact with your SiteCollection. Sure, it is possible to connect to various SiteCollections, but it's not possible to look over all SiteCollections sitting within a SPWebApplications.
In 2010 you could still use the ASMX WebServices which are available in earlier versions of SharePoint.
To get a better understanding of the CSOM you should have a look at the MSDN site http://msdn.microsoft.com/en-us/library/ee537247.aspx
Did you really mean a list containing all SiteCollection URLs or was that a misunderstanding?
Thorsten

Related

I am making the app in sharepoint, however i am not able to find the api in the sharepoint to resolve the issue

The API that I need from the sharePoint is mention below:-
How to get all groups a user is a member of
Inside library permissions we have a setting to disable library data from appearing in Search, Below mention is the screenshot for which I am looking the api.enter image description here
It depends on the chosen technology, but generally:
SPUser object have the Groups property.
In CSOM:
var ctx = new ClientContext(url);
var user = ctx.Site.RootWeb.EnsureUser(userName);
ctx.Load(user.Groups);
ctx.ExecuteQuery();
https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spuser.groups?view=sharepoint-server#microsoft-sharepoint-spuser-groups
Use "NoCrawl" property from a SPList object.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.splist.nocrawl?view=sharepoint-server#microsoft-sharepoint-splist-nocrawl

Microsoft Sharepoint 2010-Connecting to a remote site and fetching changelogs

My problem is simple. I have a registered Sharepoint site/domain (say https://secretText-my.sharepoint.com/personal/blabla) and I want to fetch the changelogs as described here Sharepoint Change log
So my question boils down to >>> How can I use this Changelog API to fetch data for a remote Sharepoint site?
How can I achieve this? I have tried Client Object Model and everything related but my goal is to use Sharepoint Change log.
I am hoping for something like,
using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext("https://secretText-my.sharepoint.com/personal/blabla"))
{
if (ctx != null)
{
ctx.Load(ctx.Web); // Query for Web
ctx.ExecuteQuery(); // Execute
ctx.Load(ctx.Site);
ctx.ExecuteQuery();
SPSite site = new SPSite(ctx.Site.Id);
SPContentDatabase db = site.ContentDatabase;
// Get the first batch of changes,
SPChangeCollection changes = db.GetChanges();
//USE this 'site' object to fetch the change logs
.
.
.
My aim is to somehow instantiate this SPSite object which would then help me get the data I want. Although this code seems a bit too ambitious(or totally wrong) but please don't hold it against me, I couldn't find any solution to this.
Much appreciated!
After a lot of Google searches and after reading so many answers, I have come to know that it isn't possible to connect to a remote Sharepoint server through the Server API. As that API works only when SP server is on the same network (same machine or intranet)
The only solution is to use Client Object Model. It provides(maps) quite a lot operations that the Server API gives.
To connect to the remote site I have used the samples provided at the MSDN site for Client Object Model. Here

create Sharepoint publishing site using Client Object model

I want to create SharePoint publishing pages using Client object model such that I can manually set the page layout.
Basically I want to know is there any way to work like that we can do in server based programming .
PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();
PublishingPageCollection pages = publishingWeb.GetPublishingPages();
PublishingPage newPage = pages.Add(pageName, currPageLayout);
newPage.ListItem.Update();

Get the SharePoint URL for a Team Project programmatically

I want to find out by coding if a given Team Project has an associated SharePoint. If yes I also want to get the URL for the SharePoint in order to create a specific link to it.
I do not mean the web access of the TFS but the associated SharePoint. Is there a way to find this out without knowing the URL of the SharePoint server that is different from the TFS server?
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
private static string RetrieveProjectPortalBaseAddress(TfsTeamProjectCollection tfs, string teamProject)
{
IRegistration registration = (IRegistration)tfs.GetService(typeof(IRegistration));
RegistrationEntry[] entries = registration.GetRegistrationEntries("TeamProjects");
ServiceInterface endpoint = entries[0].ServiceInterfaces.FirstOrDefault(si => si.Name == teamProject + ":Portal");
return endpoint.Url;
}

WSS 3.0 Site Provisioning

Is there any way to do WSS 3.0 site provisioning? My client's requirement is attributes as variables that will be defined in XML format: Organization Name, Logo, Address, User and Role information. The client should be able to install this web application to any WSS production server by just defining the attributes in the XML file.
Is it possible to to write a utility to parse that well defined XML and provision the site accordingly?
It's possible to provision sites from the object model, but creating entirely customized sites is beyond the scope of a single question. To get you started, you should take a look at the SPWebCollection.Add as well as the SPSiteCollection.Add.
To create a site collection and some subsites into one of your web applications, you could use something like this:
var farm = SPFarm.Local;
var solution = farm.Solutions.GetValue<SPSolution>("YourSolution.wsp");
var application = solution.DeployedWebApplications.First();
var sites = application.Sites;
using(var site = sites.Add("/", "Root Site", "Description", 1033, "YOURTEMPLATE#1", "YOURDOMAIN\SiteCollectionAdmin", "Site Collection Admin", "admin#yourcompany.example")) {
using(var rootWeb = site.RootWeb) {
// Code customizing root site goes here
using (var subSite = rootWeb.Webs.Add("SubSite", "Sub Site", "Description", 1033, "YOURTEMPLATE#2", false, false)) {
// Code customizing sub site goes here
}
}
}
Yes, there are more than one.
Take a look at SharePoint Solution Generator which is in Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions.
You may create a site with all requirements of yours (pages, lists, document libraries...) and then generate a VS project that will create a SharePoint feature with all of your site. Then you may deploy that feature to any WSS production server.
You may alter the VS project to implement the logic to read your attributes from an additional xml file.
If the structure of your site is plain or you can save it as a template you may also write a small console application that reads the attribute xml file and create the site.
Create a regular solution, or use the aforementioned solution generator to generate the .wsp file. Then create a small console application, that expects the variables you mentioned as parameters.
With the code listed above, provision the new sitecollection from that solution, and store the entered parameters (Company name etc.) in the site in a list, or in the SPSite.Properties propertybag, from which you can then read them in custom webparts etc..
The SharePoint Data Population Tool available on CodePlex allows you to define sites with XML.

Resources