How to save a site as template (WSP) and then import necessary files from that WSP in VS 2010 and deploy to another site or site collection?

In SharePoint 2010, there is a nice feature provided by VS 2010 which lets the developer import the WSP into VS 2010 environment where you can select your necessary lists, libraries, reusable workflows and see all these in code view in Visual Studio environment. You can later on deploy this to any site or site collection on your server. Important thing to note that, VS 2010 only allows you to deploy locally which means you cannot deploy anything if your SP server exists elsewhere.

First, let us see how easily you can save a site as a template from the web interface:

Go to site settings of your site. From “Site Actions”, select “Save Site as Template” (Publishing feature needs to be enabled for a site to view this option for a site [not site collection])

 

image

Now, Fill up the name of the file which will be saved as. You can select “Include Content” if you want your custom forms and custom reusable workflows to be available in the solution package. If you keep it unselected, it will not save any custom forms or reusable workflows.

image

Now, after clicking “OK”, you will be redirected to the page where the solution package is saved as template. Click on the file to download and save it.

After saving the WSP file, open your Visual Studio 2010 in “Administrator” mode and follow the steps below:

image

Choose “Import SharePoint Solution Package” from Installed templates.

image

Specify your site or site collection URL.

image

Browse to the location where you saved the “WSP” file.

image

After clicking on “Next”, you will see all the files available inside that WSP.

image

Now, you can deselect all and select only the required ones; after click on “Finish” you may get this window which will show a warning about the dependencies. Click “Yes” if required.

 

image

 

After that you will get a message saying “The solution is imported successfully”.

image

Now, you will be able drill down into all the fields you chose before and see the code for each field in VS. After modifying (if you require so), you will need to click on “Deploy” to deploy the site to your preferred location (which you mentioned while creating the project, you can change the URL from Solution Explorer too).

Once deployed, you will be able to see the elements in your site’s “All Site Content” and the settings for the lists and libraries will be exactly as it was in the other site settings from where you saved the template.

How to use Inline Code In SharePoint Designer 2010?

SharePoint 2010 does not allow inline coding for Form pages created from SP Designer. If you use inline coding in any form page (New, Edit or Display), you will get into an error which will say “Code Block is not allowed on this page”.

To resolve this, you need to change the web.config file of your web application.

For example: If your web application uses Port 80,  you have to go to to port 80 directory which generally resides in C:\inetpub\wwwroot\wss\VirtualDirectories\80

go inside that port number directory where you will find the web.config file where you will need to modify. Look for the tag <PageParserPaths> in the web.config.

Now, if you want to allow inline coding for all the site collections under that web application you will need to add the following:

<PageParserPaths>
        <PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>

Now, above code will allow inline coding in all the form pages in SharePoint Designer 2010 under that particular web application across all the site collections and sites. Use IncludeSubFolders=”true” if you want that coding enabled for all the site collections or sites under that web app.

If you want to allow inline coding only for a particular site collection you will need to change the code to the following:

<PageParserPaths>
        <PageParserPath VirtualPath="/sites/sitename/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
 </PageParserPaths>

 

For a particular page inside a site or site collection:

<PageParserPaths>
        <PageParserPath VirtualPath="/sites/sitename/PageName.aspx" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>

Change the PageName.aspx to your page name.

For master page of your root level site collection:

<PageParserPaths>
    <PageParserPath VirtualPath="/_catalogs/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>

 

How to solve web service access problem for an anonymous enabled site in SharePoint 2010?

Recently, I was trying to build an InfoPath 2010 form in SP 2010 where I created Data Connection using UserProfileService.asmx web service within my site collection. Although, while setting up the connection I didn’t face any problem and I could see all the properties in the advanced mode for that data connection. I checked the Web Service URL directly to see the methods which would return me the required parameter.

After configuring everything, I was getting an error which stated “Unauthorized operation” while previewing the form in InfoPath:

The SOAP response indicates that an error occurred on the server:

Server was unable to process request. —> Unauthorized operation

I realized that some permission issue need to be resolved. I then contacted our Administrator to configure the InfoPath form services settings from the Central Admin site.

There are few things which you need to know before you can use the web services such as UserProfileService.asmx.

There is a service application in SharePoint named as “User Profile Service” which need to be set up or could be setup already in your farm. I will not go into the details of configuring it. After activating this service, the user who need to access the web services related to this, need to have have full permission access for this service which you can configure by selecting the service (Central Administration->Application Management->Manage Service Account) and adding the user in two categories (Administration and Permission), both of which require to provide full access for that particular user.

image

image

After spending enough time, I figured out that although, my web application was anonymously enabled, SharePoint does not allow the web services to run anonymously by any means. It has to pass through authentication in the IIS.

There are few workarounds which you can follow:

First Option: If your web application uses Windows Authentication (To Check, which authentication your web application is using, go to Central Admin->Application Management->Manage Web Applications; select your web app and click on “Authentication Providers”, under Membership zone, click on “Default”; under Authentication Type, you will see whether your site is using Windows, Forms or Single Sign on), Disable Anonymous Access for this web application and the web service will run perfectly (Remember, if you disable anonymous access at the web app level, all the site collections under that web app will automatically disable anonymous access option). This option is an easy way to fix the web service access problem if all the site collections for your web app really does not require anonymous access.

Second Option: (If you want to enable “anoymouos access”)

To let the users access your site anonymously, and at the same time to access the web service within that web app or site collection level, you will need to change your Authentication Type from “Windows” to “Form Based”. Now, I will not go into the detailed steps of configuring form based authentication for your server which is described here.

Third Option: (The Best one which suited me)

Actually, if you want to keep intact all the settings of your existing web app, and don’t want to mess up the settings, this option could be the best one for you. First of all, you will need to extend your web application for Intranet use. To do this

Go to Central Admin->App Management->Manage Web App, select your web app and select “Extend” from the ribbon.

image

You will find the following window:

imageimage

Select the Public URL Zone as “Intranet”. and make sure to Disable Anonymous Access.

Let’s say your Default Zone URL is : http://teams.SPWebApp.com/ then the extended Web Application URL would be : http://servername:portnumber/

Now, while calling the web services from InfoPath, you will need to provide the Extended Zone (Intranet) URL and things will work like charm. That means, when the web services will be called from your forms, it will call the Intranet URL which has “Anonymous Disabled” which will not interfere with your Default Zone URL which has “Anonymous Enabled”. So, you will be able to use Windows Form Authentication while providing the anonymous access feature to the users to call your required web services. Now, that’s a great workaround to avoid setting up “Form Based Authentication” (second option).