Can anyone tell me if I have some ways to access to sharepoint list from windows app?
I've tryed following way (i'm under user that is sharepoint member):
SPUserToken token = new SPUserToken(
BitConverter.GetBytes(WindowsIdentity.GetCurrent().Token.ToInt32()));
SPSite site = new SPSite(siteName, token);
but no luck...
Your best bet is to use a web reference to query the SharePoint WebService's GetListItems web method:
http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems.aspx
Like Jason said, to be able to use the SharePoint Object model (i.e. the sharepoint dll's) the app needs to be running on the same machine as SharePoint. If it is anywhere else you can only use the Web Services provided by SharePoint (or create your own and deploy that to your sharepoint server).
P.S. In SharePoint 2010 you have the client object model at your disposal, basically a subset of the full sharepoint object model (Kinda like Silverlight). Of course sp2010 is still in beta....
This article provides an excellent and detailed step by step tutorial on how to do this using Linq and Web services. It does create a console application instead of a Windows application but it is very easy to translate this into a Windows Form app if needed. I found this article very useful when I started working on programatically communicating with SharePoint lists because it clearly demonstrates how easy it is to work with the web service response from SharePoint using LINQ.
Is siteName on the same computer that you are running the windows application from? If not, then you won't be able to access that site if you're using SharePoint 2007.
If the above isn't the problem, then check that the user account WindowsIdentity.GetCurrent() is at least a site owner on siteName.
Related
I want to create a web application that uses a custom database with a web api where javascript calls the api from html pages to perform basic crud operations.
The end game though is to surface this through SharePoint 2013 as a provider hosted application.
Can anyone advise on how I might go about this? I am particularly wondering how making ajax api calls to the application via the html pages surfaced from within sharepoint 2013 will work and authenticate.
Is the application using SharePoint data or are you just using your custom database? If you are just using your custom database, you can use the page viewer web part to display the application: http://office.microsoft.com/en-us/sharepoint-foundation-help/display-a-web-page-on-a-sharepoint-page-by-adding-the-page-viewer-web-part-HA101857182.aspx
If you are consuming SharePoint data, that is a different beast and your best bet is reading the docs here: http://msdn.microsoft.com/en-us/library/office/fp142381(v=office.15).aspx
Here's the scenario:
We have an external SharePoint instance with anonymous access turned on. We want the document libraries open to the public. We do not want custom lists open. That was simple enough to configure.
Now we want to use those lists to create an attractive external ASP.Net web application. This web site will need anonymous enabled as well.
The problem is we need to access those lists from the web application without opening them to anonymous access.
We want to use the API (not web services) since this will be hosted on the same boxes.
So far we have been unable to create an SPUser with the appropriate access to open the lists.
SPContext is empty.
Doing this fails as well:
SPSite temp = new SPSite(URL);
SPUserToken token = temp.SystemAccount.UserToken;
SPSite site = new SPSite(URL, token); ...do stuff as the user.
RunWithElevatedPrivileges also fails.
Please help!
Any chance you are using SharePoint 2010? They have more options available to access from other applications. If not 2010, you are going to have to use a web service of some kind, either the OTB ones or your own Web Service that encapsulates your logic since the SP OM will not run on a non SharePoint box.
Independent of that, you could try getting the SPToken from the Application pool. Essentially
SPUserToken sysToken = SPContext.Current.Site.SystemAccount.UserToken;
using(var systemSite = new SPSite(SPContext.Current.Site.ID, sysToken))
Daniel Larson is a big proponent of this approach over using RunWithElevatedPriveleges. Check out his blog post on the matter.
I want to create a SharePoint list using SharePoint web services (instance is SharePoint Services v3.0). That list should be built from the custom list template that I have created previously. Browsing through MSDN documentation resulted in the following resolutions:
services.ListsService.AddList(title, description, templateID);
or
services.ListsService.AddListFromFeature(title, description, featureGUID, templateID);
Now, if we take a look at the first implementation, there is a problem as the templateID doesn't exist for my custom template - it refers to the default ones instead.
The second implementation is no good either as I need the templateID again, but I also need the feature GUID which I have no idea how to get. Could anyone help please? Thanks.
It has been confirmed to me from people from Microsoft that, unfortunately, it is not possible to utilize features to create a SharePoint list using SharePoint web services. It can be either done by developing custom web service, or by using Object Model.
UPDATE
I can now perform succesful UI impersonation. This was an issue with the code I was using and after viewing Jay Nathan's article I have reverted to his code and all is working great.
In response to a comment this is the code I am using to create a new site collection:
Dim newSite As SPSite = webApp.Sites.Add( _
txtWebApp.Text & "/cg/" & strURL, txtName.Text, txtDesc.Text, 1033, "SITEDEF#0", _
"DOMAIN\ACCOUNT", "NAME", "EMAIL", _
"DOMAIN\ACCOUNT", "NAME", "EMAIL")
and yes "SITEDEF#0" is a perfectly valid site defintion.
Hopefully I have overcome this issue by using an Application Page which is available as an element on the Site Actions menu (to site admins only). Using impersonation I can succesfully instigate this process. There are some additional issues which I have highlighted in another question.
ORIGINAL QUESTION
I have a need to allow non farm administrators to be able to create site collections using a very specific site definition. These people will not have access to central admin and so require a custom solution to allow the creation of these. I have tried several solutions, but want some consensus on a recommended approach.
Custom Web Service - I have written a custom web service to perform this task however this caused major headaches and even though the web service was running in an app pool using the same identity as the sharepoint app pool I could not get this to work. Also had form digest issues in trying to perform this v ia a web service.
Web Part/Application Page - No form digest issues here as we are in the SharePoint context, however I have tried using RunWithElevatedPrivileges but I still get an access denied when calling SPWebbApplication.Sites.Add(), even though all SPSite and SPWeb pbjects are being instantiated inside the elevated code block. I have tried direct impersonation at the UI level and I get an UnhandledException saying that impersonation has failed.
Application Wrapper Around stsadm - I have not attempted this yet as I am concerned about the viability of this approach, surely there is a cleaner way than this?
Some guidance on this would be useful as I cannot find much out there on this.
Thanks
I'd go with option number 1. It's probably an authorization issue. How are you accessing SharePoint? with the SDK or trough its web services?
I'd go for number 2. That code should work, maybe the impersonation code is not correct? You can't use SPContext like you normally would for instance.
Also, you are elevating to the identity of the application pool of your SharePoint site. Does this account have sufficient rights to create Site Collections?
You can check in Central Administration > Application Management > Policy for Web Application.
Is there any MOSS out of the box web service which allows us to check if a user has access to a document library if I know the URL for the document library. I have the URL for the SharePoint document library, user name and password.
Thanks.
Yes, please if a user has "Read" permission on document library. If there is no out of the box web service, and we develop our own web service, does this need to be deployed on a server where MOSS is insalled?
Nothing OOB with MOSS 2007/ WSS 3.0
Check out SharePoint Sushi
for a useful library that may help you either as a starting point or as a component in your final solution.