Category: Uncategorized

How to get list of SharePoint Lists in SharePoint 2013 Online using CSOM

Home | Uncategorized | How to get list of SharePoint Lists in SharePoint 2013 Online using CSOM

In this post, we’ll see how to get the list of the SharePoint List in SharePoint 2013 Online using CSOM.

Open Visual Studio 2013.

File –> New –> Project –> Visual C# –> Console Application  and name it as ‘ReadSharePointLists’

Add a reference to assemblies ‘Microsoft.SharePoint.Client’ and ‘Microsoft.SharePoint.Client.Runtime’.

Import the following two namespaces.

using Microsoft.SharePoint.Client;
using System.Security;

Copy and paste the following snippet of the code that will help us to fetch the list of SharePoint lists in the SharePoint Online site.

namespace ReadSharePointLists
{
    class Program
    {
        static void Main(string[] args)
        {
            //Replace it with the url of your tenant or your site-collection
            string SiteUrl = "https://yoursite.sharepoint.com";

            System.Uri oUri = new System.Uri(SiteUrl);

            using (ClientContext oClientContext = new ClientContext(SiteUrl))
            {
                //Replace it with your user id for SharePoint Online
                string UserName = "userid@yoursite.onmicrosoft.com";


                //Replace it with your password
                string Password = "password";

                //Create a SecureString object from password string, needed for SharePointOnlineCredentials class
                SecureString SecurePassword = GetSecureString(Password);
                oClientContext.Credentials = new SharePointOnlineCredentials(UserName, SecurePassword);

                //load the properties of web object
                Web oWeb = oClientContext.Web;
                
                //Get all the lists in the web
                oClientContext.Load(oWeb.Lists);
                oClientContext.ExecuteQuery();


                foreach (List oList in oWeb.Lists)
                {
                    Console.WriteLine(oList.Title.ToString());
                
                }
                Console.ReadLine();


            
            }

        }

        private static SecureString GetSecureString(String Password)
        {
            SecureString oSecurePassword = new SecureString();

            foreach (Char c in Password.ToCharArray())
            {
                oSecurePassword.AppendChar(c);

            }
            return oSecurePassword;
        }

    }
}

 

After executing this we’ll see the below result, which displays the names of the SharePoint lists in the SharePoint 2013 Online site.clip_image002

 Subscribe to my blog

Configure internet access in Microsoft Azure Virtual Network

Home | Uncategorized | Configure internet access in Microsoft Azure Virtual Network

I’m setting up a Virtual Network in Azure to host my SharePoint 2013 farm. I’ve configured added the DNS servers of 10.0.0.4 and 10.0.0.5 (as per my pervious article), expecting that I would be able to access the public internet inside the SharePoint 2013 VM’s. I’m able to access only google and few other internet sites inside the VMs, most of the sites including microsoft.com was not accessible.

The fix for this issue is to add the Public DNS servers (168.63.129.16 and 168.62.167.9) to the list of DNS servers in the Azure Virtual Network.

image

After adding the Public DNS servers (168.63.129.16 and 168.62.167.9) , the internet connectivity worked like a charm.

 Subscribe to my blog

How to create a site-collection using CSOM in SharePoint Online

Home | Uncategorized | How to create a site-collection using CSOM in SharePoint Online

In this post, we’ll see how to create a site-collection using SharePoint 2013 CSOM in SharePoint Online. We’ll be using a console application for the purpose of demonstration.

Open Visual Studio 2013 –> File –> New –> Console Application and name it as ‘CreateSiteCollCSOM’.

Add references to the following assemblies

Microsoft.SharePoint.Client.dll

Microsoft.SharePoint.Client.runtime.dll

Microsoft.Online.SharePoint.Client.Tenant.dll

.

The Microsoft.Online.SharePoint.Client.Tenant.dll will be available in the location C:Program FilesSharePoint Client ComponentsAssemblies, if the SharePoint Client Components SDK is installed.

Import the following namespaces at the top of Program.cs

using  Microsoft.SharePoint.Client;
using System.Security;
using Microsoft.Online.SharePoint.TenantAdministration;

static void Main(string[] args)
        {
            


            using (ClientContext oClientContext = new ClientContext("https://yoursite-admin.sharepoint.com"))
            {
                //Assign User Id for your SharePoint Online tenant     
                string UserName = "userid@yoursite.onmicrosoft.com";

                //Assign password for your SharePoint online tenant
                string Password = "password";

                //Create a SecureString object from password string, needed for SharePointOnlineCredentials class
                SecureString SecurePassword = GetSecureString(Password);

                oClientContext.Credentials = new SharePointOnlineCredentials(UserName, SecurePassword);
                

                var oTenant = new Tenant(oClientContext);

                var oSiteCreationProperties = new SiteCreationProperties();


                //Set the url of site-collection to be created
                oSiteCreationProperties.Url = "https://yoursite.sharepoint.com/sites/TestSiteColl";

                //Set the title of site
                oSiteCreationProperties.Title = "Test SiteColl from code";

                //set the site-collection owner
                oSiteCreationProperties.Owner = "userid@yoursite.onmicrosoft.com";

                //set the template of site-collection to be created as TeamSite
                oSiteCreationProperties.Template = "STS#0";

                //set the storge maxium level in MB
                oSiteCreationProperties.StorageMaximumLevel = 200;

                oSiteCreationProperties.UserCodeMaximumLevel = 100;



                SpoOperation oSpoOperation = oTenant.CreateSite(oSiteCreationProperties);

                oClientContext.Load(oTenant);

                oClientContext.Load(oSpoOperation, i=>i.IsComplete);
                oClientContext.ExecuteQuery();

               

                Console.WriteLine("SiteCollection successfully reated");




            }




        }

        private static SecureString GetSecureString(String Password)
        {
            SecureString oSecurePassword = new SecureString();

            foreach (Char c in Password.ToCharArray())
            {
                oSecurePassword.AppendChar(c);

            }
            return oSecurePassword;
        }

SharePoint Multitenancy – Faqs–Part 2

Home | Uncategorized | SharePoint Multitenancy – Faqs–Part 2

This post is the continuation to my previous post tiled SharePoint Multitenancy – Faqs

1. What are multiple ways in which customer sites can be deployed a SharePoint farm enabled with multi-tenancy ?

  • Dedicated application pool and Web application
  • Shared application pool and dedicated Web application
  • Authenticated Sites
  • Unauthenticated Sites
  • Shared Web application

2.  When to choose dedicated web applications for tenants ?

If the customizations required for tenants affect the resources that are shared across a web application, such as a web.config file

3. What will be the recommended strategy when multiple tenants need to be combined in a single web application ?

While combining multiple tenants into one, it is recommended to have one dedicated web application for authenticated content of all the tenants and another dedicated tenant for all unauthenticated content for all the tenants. Finally, it will require two different subscription IDs for tenants for both the types of content. This approach also will make the licensing simpler.

4. What are the factors to be considered while deploying customizations to a multi-tenant environment ?

The following factors need to be considered while deploying customizations to multi-tenant environment :-

  • Do not allow full-trust code to be deployed to the sites
  • Do not allow the customizations that require changes to the shared resources like web.config file
  • Use host named site-collections to create multiple root-level site-collections (domain-named sites) within a web application

5. What is the factor to be considered when the tenant must span 1 database ?

If the tenant needs to span more than 1 database, there must one and only tenant in all those databases (dedicated content databases for a tenant)

6. What is the factor to be considered when the multiple tenant needs to share a database ?

If a tenant needs to share a database with another tenant, those tenants should NOT span databases.

7. How a hosted environment can be scaled out ?

The hosted environment can be scaled out by creating separate set of farms.

a)Services farm – A dedicated services farm can be created for all the services (applicable) that can be shared across farms.

b)Search farm – A dedicated farm can be created to host Search

c)Tenant content farm – Tenant content farms can be scaled out in a similar way as the services farm

8. What is Organizational Units (OU) of Active Directory and how its is relevant in the context of SharePoint hosting?

Organizational units are used to organize users and computer objects in the Active Directory environment. The same Organizational Unit for SharePoint is illustrated below :-

organizational units IU

9. What is the role of Domain Root ?

The Security policies that need to be applied to the entire domain is applied in the Domain policy. They are configured in the GPOs that apply to the entire domain.

10. What is the role of Domain Controllers OU ?

It holds the most sensitive data in the organization, the data which controls the security configuration itself. GPOs are applied at this level to protect the domain controller.

11. What is the role of SharePoint Server OU ?

It has unique role not included in other servers in the directory. It can be placed in its own OU to allow unique policies to be applied on the servers. It can also be segregated from other servers in the directory.

12. What is the role of customers OU ?

The Customer OU (top-level OU) allows all users accounts to be segregated from the rest of the directory. The next level OU would be the respective customer’s OU (like Customer A OU or Customer B OU). In order to give the users the impression they are logging into their own customer domain, use ADSI Edit or another Active Directory tool to edit the uPNSuffixes attributes.

 Subscribe to my blog

Publish Access Web Database to SharePoint 2010 Access Services

Home | Uncategorized | Publish Access Web Database to SharePoint 2010 Access Services

Here are the pre-requisite for publishing the access web database to access services.

1. Install Microsoft SQL Server 2008 R2 Reporting Services add-in for SharePoint Technologies 2010 and configure it.

image_thumb

2. Create a service account (in Active Directory) to run the application pool of Access Services

3. Register the service account as the managed account in the central administration

4. Start the Access Service application

 

In order to make the access database publishable to SharePoint 2010 Access Services, create the access database using ‘web database’ template in access 2010.

image

Now we can create the required set of tables within Access Web Database. The next step is to publish the access web database to SharePoint 2010 Access Services

1. File –> Save & Publish

2. Click ‘Publish to Access Services’

3. Enter Server Url and Site Name

accesswebdb1

 Subscribe to my blog

SharePoint 2010 Recommended practices for disposing objects–Part2

Home | Uncategorized | SharePoint 2010 Recommended practices for disposing objects–Part2

This post is the continuation of the post titled SharePoint 2010 Recommended Practices for disposing objects – part1

1. Disposing Framework Created Objects

a)The SPSite objects created through ‘Add’ method of SPSiteCollection class should be disposed explicitly. This is not managed by the Framework. Only objects created from SPContext is managed by the Framework.

SPWebApplication oSPWebApplication = new SPSite("http://yoursitecollection").WebApplication;

SPSiteCollection oSPSiteCollection = webApp.Sites;

using (SPSite oSPSiteCollection = siteCollections.Add("sites/myNewSiteCollection", "DOMAIN\User", 

"test.user@testdommain.com"))

{

}

b)Explicitly Dispose SPSite objects created through SPSiteCollection[Index] property. Because accessing SPSiteCollection[Index] property

returns a new instance of SPSite object. This needs to be explicitly disposed. In the following case, the oSPSiteNew object needs to be explicitly disposed either using try-finally or using clause.

using (SPSite oSPSSiteOuter = new SPSite("http://yoursitecollection"))

{

SPSite oSPSiteNew = null;

try

{

SPWebApplication oSPWebApplication = oSPSiteInner.WebApplication;

SPSiteCollection oTempSiteCollections = webApp.Sites;

oSPSiteNew = siteCollections[0];

}

finally

{

if (oSPSiteNew != null)

oSPSiteNew .Dispose();

}

}

c)Explicitly dispose SPSite objects accessed inside for-each loop using try-finally clause.

foreach (SPSite oSPSiteTemp in siteCollections)

{

try

{

// ...

}

finally

{

if(oSPSiteTemp != null)

oSPSiteTemp.Dispose();

}

}

d)Explicitly dispose SPWeb objects created through Add method (SPSite.AllWebs.Add Method) of SPWebCollection class.

using (SPSite oSPSite = new SPSite("http://yoursitecollection"))

{

using (SPWeb oSPWeb = oSPSite.AllWebs.Add("site-relative URL"))

{

} // oSPWeb is automatically disposed by Using clause

} // oSPSite is automatically disposed by Using clause

e)Explicitly Dispose SPWeb objects accessed through SPWebCollection[Index] property. Because accessing SPWebCollection[Index] property returns a new instance of SPWeb object. This needs to be explicitly disposed. In the following the object oSPWebNew needs to be explicitly disposed by using clause or try-finally clause.

using (SPSite oSPSite = new SPSite("http://yoursitecollection"))

{

using (SPWeb oSPWeb = siteCollection.OpenWeb())

{

SPWebCollection webCollection = oSPSite.AllWebs; 

using (SPWeb oSPWebNew = webCollection.Add(strWebUrl))

{

//this will dispose oSPWebNew

}

} // 

}

f)Explicitly dispose SPWeb objects accessed inside for-each loop using ‘try-finally’ clause

foreach (SPWeb oSPWebNew in oSPSite.AllWebs)

{

try

{

// ...

}

finally

{

if(oSPWebNew != null)

oSPWebNew.Dispose();

}

}

2.Disposing SPWeb objects created through SPSite.OpenWeb()

Explicitly dispose SPWeb objects created through OpenWeb method. Because OpenWeb method creates a new instance of SPWeb object, which is not managed by the framework

using (SPSite oSPSite = new SPSite("http://yourserver"))

{

using (SPWeb web = oSPSite.OpenWeb())

{

} // SPWeb object web.Dispose() automatically called.

}

3.Disposing SPSite objects accessed through SPSite.RootWeb property

a)Do not explicitly dispose SPSite.RootWeb property. This does not hold good for SharePoint Server 2010 and SharePoint Foundation 2010 anymore. The RootWeb property is internally disposed by SP Foundation 2010 or SP Server 2010

b)Do not explicitly call Dispose method on SPSite.RootWeb property

4.Disposing SPSite objects created through Microsoft.Office.Server.UserProfiles.PersonalSite

Explicitly dispose SPSite objects created by accessing that Microsoft.Office.Server.UserProfiles.PersonalSite property

using (SPSite siteCollection = new SPSite("http://yoursitecollection"))

{

UserProfileManager oUserProfileManager = new UserProfileManager(ServerContext.GetContext(siteCollection));

UserProfile oUserProfile = oUserProfileManager.GetUserProfile("domain\username");

using (SPSite oSPSiteNew = oUserProfile.PersonalSite)

{

//enclosed using clause will take care of disposing SPSite objected created by accessing the PersonalSite property

}

}

 Subscribe to my blog

Programmatically update Infopath Form XML using c# code

Home | Uncategorized | Programmatically update Infopath Form XML using c# code

This article would share a code-snippet that updates the Infopath form XML.  In my portal, I’m performing data-acquision using Infopath forms for a Infopath-content type workflow scenario. This scenario is all about an employee appraisal workflow. I’ve a business requirement to mark the ‘IsManager’ column as ‘Yes’ , when the employee gets promoted as Manager. This forced me to think a way to programmatically update the Infopath form XML using c# code. The following is the c# code that can be used to programmatically update the Infopath Form XML.

                        SPWeb   oWeb = SPContext.Current.Web;                       
                        SPList _list = oWeb.Lists[“TestFormLib”];
                        MemoryStream oMemoryStream = new MemoryStream(item.File.OpenBinary());
                        XmlTextReader oReader = new XmlTextReader(oMemoryStream);

                        XmlDocument oDoc = new XmlDocument();
                        oDoc.Load(oReader);

                        oReader.Close();
                        oMemoryStream.Close();

                        XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(oDoc.NameTable);
                        nameSpaceManager.AddNamespace(“my”, “http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-11T12:44:57“);

                        doc.DocumentElement.SelectSingleNode(“my:IsManager”, nameSpaceManager).InnerText = “Yes”;
                        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                        SPFile oSPFile = oWeb.Folders[“TestFormLib”].Files.Add(item.File.Name.ToString(), (encoding.GetBytes(doc.OuterXml)), true);
                        item.File.Update();

 

 Subscribe to my blog

Office 365 ondemand web casts

Home | Uncategorized | Office 365 ondemand web casts

I tried to collate the list of office 365 webcasts that are published this month (July 2011). They are listed below:-

Office 365 Jump Start: Microsoft Office 365 Overview for IT Pros

http://technet.microsoft.com/en-us/edge/video/office-365-jump-start-01-microsoft-office-365-overview-for-it-pros

 

Office 365 Jump Start: SharePoint Online Overview

http://technet.microsoft.com/en-us/edge/office-365-jump-start-12-sharepoint-online-overview

 

Office 365 Jump Start: SharePoint Online Administration

http://technet.microsoft.com/en-us/edge/office-365-jump-start-13-sharepoint-online-administration

 

Office 365 Jump Start: SharePoint Online Extensibility & Customization

http://technet.microsoft.com/en-us/edge/ce-365-jump-start-14-sharepoint-online-extensibility-customization

 

How Microsoft IT does Business Intelligence

http://blogs.technet.com/b/tothesharepoint/archive/2011/06/06/how-does-microsoft-do-bi.aspx

Visio 2010 does not show option to create SharePoint 2010 Workflows

Home | Uncategorized | Visio 2010 does not show option to create SharePoint 2010 Workflows

I’ve installed the Visio 2010 Professional and tried to design SharePoint 2010 workflow. Surprisingly, i did not get the option to design SharePoint 2010 workflow.

 visio1

I’ve learnt that Microsoft Visio Professional 2010 does not support designing SharePoint 2010 workflows. The solution is to upgrade to Visio Premium 2010 to get the SharePoint Workflow 2010 templates.

visio2

 Subscribe to my post

Silverlight debugging problem: The Silverlight managed debugging package is not installed

Home | Uncategorized | Silverlight debugging problem: The Silverlight managed debugging package is not installed

I’m involved in developing Silverlight 3.0 development. My environment i s.NET 3.5 SP1, VS 2008 SP1 and Silverlight 3.0. It was working fine until i upgraded the silverlight runtime 4.0. I’m getting this error “Unable to start debugging. The Silverlight managed debugging package is not installed”.

I’ve learned that the fix for this is to install the Silverlight 4.0 install for developers http://go.microsoft.com/fwlink/?LinkID=188039

After installing this hotfix, i could able to debug Silverlight 3.0 applications in VS 2008, with Silverlight 4.0 installed side-by-side.

 Subscribe to my post