Showing posts with label Office365. Show all posts
Showing posts with label Office365. Show all posts

Wednesday, 5 March 2014

View Tenant (ULS) Logs in SharePoint Online using CSOM

Update (14th Sep 2014): Even though the classes exist in the CSOM, the Microsoft Office 365 Engineering team has confirmed that this is something which is not possible right now. It is also something which is not currently on their road map. They have said that if there is high demand for this feature, they will look into implementing it. Please go to the Office 365 UserVoice site and vote this feature up if you are interested: http://officespdev.uservoice.com/forums/224641-general/suggestions/4578386-provide-a-way-to-view-uls-logs-on-sharepoint-onlin

----------------------------------------------------------X-------------------------------------------------

A while ago, I came across the Office365 UserVoice site. It was a good way to give feedback and let the SharePoint/Office365 team know which features could make the life of SharePoint Developers easy.

I decided to post on it a feature request, which I felt was desperately needed and would really help me as a SharePoint Developer: A way to view ULS Logs on SharePoint Online
http://officespdev.uservoice.com/forums/224641-general/suggestions/4578386-provide-a-way-to-view-uls-logs-on-sharepoint-onlin

It seems this was a shared opinion among many people and the request went on to become one of the top voted on the site:
http://officespdev.uservoice.com/forums/224641-general/filters/top

Fast Forward to today and I was really excited about the SharePoint Conference 2014! I saw a lot of code samples and articles being published as a result of the new features introduced by the SharePoint Team. While exploring the Office App Model Samples (http://officeams.codeplex.com/) I came across the following DLL: Microsoft.Online.SharePoint.Client.Tenant.dll

You can refer to my previous post about using this DLL to create Site Collections in SharePoint Online:
http://www.vrdmn.com/2014/03/create-site-collections-with-csom-in.html

I opened up the DLL in ILSpy and immediately noticed the TenantLog class:
http://msdn.microsoft.com/en-us/library/microsoft.online.sharepoint.tenantadministration.tenantlog_members(v=office.15).aspx

After playing around it a bit, I was able to retrieve Log messages from my Tenant. This seems to be a preview feature still in development and was not working on all the tenants on which I tested. In fact, it was working only on a newly created Tenant! That too only for the Developer Site.

Having a look at the MSDN docs for the SPO PowerShell cmdlet:
http://technet.microsoft.com/en-us/library/fp161369(v=office.15).aspx

"This function cannot retrieve all SharePoint Online errors. It retrieves a subset of errors that happen due to external systems.
For Beta 2, the only logs available are for Business Connectivity Services (BCS)."

I will keep this post updated with any new information which comes along.

You will need the following DLLs for this code to work:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.Online.SharePoint.Client.Tenant.dll

The first two assemblies can be found in the ISAPI folder of your SharePoint 2013 Server Box. The Microsoft.Online.SharePoint.Client.Tenant.dll is a part of  the SharePoint Server 2013 Client Components SDK which can downloaded from here: http://www.microsoft.com/en-in/download/details.aspx?id=35585

So without much further ado, here is the code:
And here is the output I got after running the code:


I think the SharePoint team has done a really great job of listening to the community to add new features to SharePoint/Office365 and I am really happy!

Tuesday, 4 March 2014

Create Site Collections with CSOM in SharePoint Online

With the SharePoint Conference 2014, a lot of code samples and articles where recently released. I was most impressed by the Office App Model Samples found here: http://officeams.codeplex.com/

Within that, there is some really good code of which my favorite is Creating Site Collections in SharePoint Online with CSOM. Previously this was only possible via Powershell and the SharePoint Online (SPO) Commandlets. I have modified the code provided in the samples to make it a bit less complex and you can also use it outside of an app e.g. in console applications.

You will need the following DLLs for this code to work:
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.Online.SharePoint.Client.Tenant.dll

The first two assemblies can be found in the ISAPI folder of your SharePoint 2013 Server Box. The Microsoft.Online.SharePoint.Client.Tenant.dll is a part of  the SharePoint Server 2013 Client Components SDK which can downloaded from here: http://www.microsoft.com/en-in/download/details.aspx?id=35585

So without much further ado, here is the code:

Saturday, 12 January 2013

Authenticating .NET CSOM in SharePoint Online

The process of authenticating the .NET Client Object Model in SharePoint Online has been greatly simplified in the 2013 version. Earlier (2010), you had to go through a lot of steps for doing the exact same thing. You  had to open a web browser instance, force the user to enter the credentials in the browser and then grab that  cookie from Internet Explorer and pass it to the .NET CSOM. If you are interested, the code of the old authentication method can be found here:
http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx

Fortunately in the 2013 version, the process is a lot simplified by the introduction of the SharePointOnlineCredentials class. This class is part of the Microsoft.SharePoint.Client.dll itself so you don't have to include an extra assembly in your application. All you have to do is pass an instance of the SharePointOnlineCredentials class to the ClientContext.Credentials property. The SharePointOnlineCredentials takes in two parameters which are your Login Email for your Office 365 SharePoint site and your password in the SecureString format.

You can grab all the required SharePoint 2013 client assemblies from here:
http://www.microsoft.com/en-us/download/details.aspx?id=35585

For this particular demo, you will need to reference the Microsoft.SharePoint.Client.dll and the Microsoft.SharePoint.Client.Runtime.dll assemblies in your project.

 The code is as follows:




Tuesday, 19 July 2011

Bing Maps Silverlight Control in Office 365

Recently, I was working on Geocoding with the Bing Maps Silverlight Control for a SharePoint 2010 Sandbox application. Everything was going awesome on my on-premise SharePoint 2010 environment but when I uploaded the application in Office 365, every time the application would load I would get a pop-up in IE asking whether to "Display Mixed Content?"

I googled for a solution and manged to learn that since the Office 365 environment was HTTPS and the Bing Maps GeoCoding web service was HTTP, I was being presented with this dialog box asking permission to display both HTTP and HTTPS content. This was also the reason why I was not getting the same pop-up on my on-premise SharePoint 2010 environment as it was also HTTP.

So the solution to this problem I thought was to find an HTTPS version of the Bing Maps GeoCoding web service so I made the following changes in my ServiceReferences.ClientConfig file:

1)Changed the URL of the web service to HTTPS
2)Changed the security mode of the basicHttpBinding from 'none' to 'Transport'

And voila! The annoying pop-up disappeared!

My final Service ServiceReferences.ClientConfig file looked like this:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IGeocodeService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="Transport" />
                binding>
            basicHttpBinding>
            <customBinding>
                <binding name="CustomBinding_IGeocodeService">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                binding>
            customBinding>
        bindings>
        <client>
            <endpoint address="https://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
                contract="GeocodeService.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
            <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc/binaryHttp"
                binding="customBinding" bindingConfiguration="CustomBinding_IGeocodeService"
                contract="GeocodeService.IGeocodeService" name="CustomBinding_IGeocodeService" />
        client>
    system.serviceModel>
configuration>

Thursday, 26 May 2011

Office 365 and Sandboxed Solutions:Exceeded the daily resource usage quota.

"The site collection containing this sandboxed solution has exceeded its daily resource usage quota."

While working with Sandboxed Solutions on Office 365, you might get this error when you try to activate your solution. I faced this error on the Small business version of Office 365 but it has been know to occur on the Enterprise version too.
There is a limited resource usage quota alloted to each SharePoint Online sitecollection. When this usage quota is exceeded (when you try to activate your solution) , this error occurs.
So far, I have found how to resolve this issue on the Enterprise Version of Office 365 only. I am afraid there is no setting on the Small Business Version (The P1 plan) to manage the allocated resources.
The solution for this issue (on the Enterprise Version) is pretty straightforward:

Go to:
Admin ->
SharePoint Online ->
Manage ->
Manage Sitecollections->
Select your Sitecollection ->
Select Resource Usage Quota -> (on the top of the page)
Enter the new value in MB of your Usage Quota in the resources textbox->
Click Save.

Done. That's all there is to it :)
Enjoy Office 365!

Monday, 25 April 2011

Office365 beta and the SharePoint 2010 Client Object Model

UPDATE: Microsoft has published the article on Authentication the Client Object Model on Office 365. You can find it here:
http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx
                                                         -------XXX-------

​I just got my Office365 beta license and configured a new Team Site in Sharepoint Online. Then I thought of accessing this new team site through the SharePoint 2010 .NET Client Object Model when I got the 403: Forbidden error code.

First, I thought that there might be some authenticaion issue so I tried accessing with both Classic Authentication and Claims based authentication.

Forms Based Authentication(Client Object Model):


clientcontext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

clientcontext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("username", "password");

Web Service Login:

AuthService.Authentication auth = new AuthService.Authentication();
auth.Url = "http://.sharepoint.com/TeamSite/_vti_bin/authentication.asmx";
auth.CookieContainer = new System.Net.CookieContainer();
AuthService.LoginResult loginresult = auth.Login("username","password");

With both the cases, it gave me the following error:

"Server was unable to process request. ---> The server was unable to process the request due to an internal error."

lists.asmx:

I tried accessing the lists of Office365 through the Lists service:

ListService.Lists list = new ListService.Lists();

list.Credentials = new NetworkCredential("username", "password");

var res = list.GetList("Documents");

but got this clear cut error:

"Server was unable to process request. ---> Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"


After some digging aroung, I found out that indeed right now, support is not there for the client object model and the only way to currently use the Client Object Model with SharePoint Online is to get the FedAuth Cookie (from fiddler) and then include that cookie in your call from the code. But this is not the best practice and is highly discouraged.

Hopefully, the Office 365 team will include the Client Object Model as soon as possible. I will update it here as soon as there is any news regarding the issue.