Wednesday, May 6, 2015

How to download all deployed wsp solution files in SharePoint



Hi,

Usually SharePoint admin guys takes backup of content DB and all physical files if they want to create replica of existing SharePoint site when actual site is down.

But that will not complete solves the solution, if there are any custom solutions already deployed.

So, admin guys needs those solution files.
To get those solution files which are deployed in SharePoint use the following power shell command to get all deployed solution files.

$pathName = "<PATH to Save files>"
foreach ($solution in Get-SPSolution)  
{
     $solid = $Solution.SolutionID
     $title = $Solution.Name
     $filename = $Solution.SolutionFile.Name
     $solution.SolutionFile.SaveAs("$pathName\$filename")
}

How to check in all checked out files in a SharePoint list using Power shell

Hi,

I have a SharePoint list which has having more than 10 folder and many sub folder in side each folder.

Again each have subfolders and document. Most of the documents are checked out.

Now i need to check in all the checked out files its big task for me to going to each document and checkin and it will takes me days.

I was searching for any other alternatives, so using content structure i can check in multiple documents at a time but i can do it at folder level. Again it will takes more time to check in all the files.

Now, again started searching for another alternative and came up with powershell script.

I got the script and am sharing that script.

*****************************Start of  Script **********************************

[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")

$site = New-Object Microsoft.SharePoint.SPSite("http://uday:43662")

$root = $site.allwebs[0]

$folder = $root.GetFolder("Shared Documents")

#============================================================

# Function Set-CheckInFolderItems is a recursive function

# that will CheckIn all items in a list recursively

#============================================================

function Set-CheckInFolderItems([Microsoft.SharePoint.SPFolder]$folder)

{

    # Create query object

    $query = New-Object Microsoft.SharePoint.SPQuery

     $query.Folder = $folder
  
    # Get SPWeb object

    $web = $folder.ParentWeb
  
    # Get SPList

    $list = $web.Lists[$folder.ParentListId]

    # Get a collection of items in the specified $folder

    $itemCollection = $list.GetItems($query)

    # If the folder is the root of the list, display information

    if ($folder.ParentListID -ne $folder.ParentFolder.ParentListID)

    {
         Write-Host("Recursively checking in all files in " + $folder.Name)
     }

    # Iterate through each item in the $folder

    foreach ($item in $itemCollection)

    {

        # If the item is a folder

        if ($item.Folder -ne $null)

        {

            # Write the Subfolder information

            Write-Host("Folder: " + $item.Name + " Parent Folder: " + $folder.Name)

            # Call the Get-Items function recursively for the found sub-solder

            Set-CheckInFolderItems $item.Folder

        }

        # If the item is not a folder

        if ($item.Folder -eq $null)

        {

            if ($item.File.CheckOutType -ne "None")

            {

                if ($item.File.Versions.Count -eq 0)

                {

                    # Check in the file

Write-Host "Check in File: "$item.Name" Version count " $item.File.Versions.Count -foregroundcolor Green

                    $item.File.CheckIn("Bulk check in By Administrator")

                }

            }

        }

    }

    $web.dispose()

    $web = $null

}

Set-CheckInFolderItems $folder

******************************  End of Script *************************************

Saturday, May 2, 2015

Slide library missing in SharePoint 2013

As per Microsoft's, Slide library has been deprecated in SharePoint 2013.

Here the reference link.

Even if you try to search for template in add an app, it will show the below screen.



What to do next?? can not i create slide library in SharePoint 2013???

NO, we can create slide library in SharePoint 2013 by using the below URL

http://<SITE URL>/_layouts/15/slnew.aspx?FeatureId={0be49fe9-9bc9-409d-abf9-702753bd878d}&ListTemplate=2100

It will ask for list name and description. Once you have clicked on Create, it will create and it looks like as below.



Sunday, April 19, 2015

Get Linked In profile details using LinkedIn OAuth2.0 API

Hi,

Today I want to share about how to get linkedin profile details into in your application(asp.net app) using linkedin OAuth2.0 API.

Here I will create one simple asp.net application and I will show how to get LinkedIn profile and display in a page.

I. Register an application on LinkedIn

To get LinkedIn profile details we need to generate/create one profile in https://developers.linkedin.com. once you create the profile it will generate one id and one secret key.
Using these two keys in your application we can get the users profile details

Here the steps to create profile and generate keys

1. Go to " https://developer.linkedin.com" then click on " My Apps" on top navigation.

2. Once you go to My Apps page its looks like as below and click on "Add new application"

3. Now enter all required information. we are creating this application in development environment so we use localhost and we use one static port number. when you are creating profile for production environment then give host url here.


4. Once you successfully created your profile, it automatically generate API Key and Secret Key

Now we will create development web application in asp.net and try to get user's profile details.


II.  Get an access token -

Here I want to give a overview on how the application works.

OAuth2 basically allows third party application, to access protected resource of a specific user. You may have seen some web applications/sites allows you to login through your Google, Facebook, LinkedIn etc accounts. As an example just try this with any mentioned account (Google, Facebook, Yahoo etc.). After giving your username password credentials you will be notified the authorities which the third party application will get if you agreed to proceed.

First we need to authenticate the application with API Key and Secret Key.

Once it is authenticated, likedin API will ask for user credentials.

If user enter correct username and password it will generate code and that code will sent back to the redirect URL.

Using the code in application will request the access token with HTTP POST request method.

if the code is validate/verified, it will generate/returns access token key with expire time.

With this access token key we can get user profile details by passing access key token in the http header request with HTTP GET request method.

The access token represent the credentials to access protected resources. So your application does not need to store resource owner's credentials, but the access token.

Here the steps to create application to get user profile details

1. Create one asp.net application using Visual Studio 2012 named it as "GetLinkedInUserProfileDetails".



2. Make sure that application run on the port number which you have given while creating profile in developer site.



3. Now we need to add LinkedIn profile API Key and Secret Key by using one class file call it as "LinkedinAuthDetails" and the class looks like as below.

4. Now design your master page and add login.aspx with one button as shown below.

when user clicked on the button, it will go to LinkedIn for application authorization.
Here the code in button click event.

 Response.Redirect("https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=" + obj.apiKey + "&scope=r_fullprofile&state=DCEEFWF45453sdffef424&redirect_uri=" + HttpUtility.HtmlEncode(obj.redirectUrl));

If the query string have correct API Key, and website URL then it will ask for user credentials.

If not it will throw an error and out put will be like this.


Once the credentials are validated then it will redirect to "RedirectUrl" which is the query string along with the code value. This code value is used to get access token for the loggedin user profile.

After successful user credential validation it is redirected to "ProfileDetails" page with code value in query string.

5. In ProfileDetails page, we have code value with this code value we will try to get access token key by using http web request with POST method.

 dynamic responseText = obj.VerifyAuthentication(Request.QueryString["code"]);

This is the method to get access key token. 

Here the method definition.




III. Make API calls - Yes, after obtaining access token you are free to call API methods with that, until it expires.

Now we will make HTTP web request to LinkedIn API for user profile details with GET method.

                        string authcode = "";
                        dynamic dynobj = JsonConvert.DeserializeObject(responseText);
                        foreach (var item in dynobj)
                        {
                            if (item.Name == "access_token")
                            {
                                authcode = "Bearer " + item.Value; break;
                            }
                        }
                        response = GetProfileResponse(authcode);

Here the GetProfileResponse method definition.


If  the HTTP request header has valid access token then it will give response with user profile details.

There the application output.






Click here for source code.

Wednesday, April 8, 2015

Basic list CRUD operations using REST API in SharePoint 2013

Hi, today i want to share how to do basic list CURD operation using REST API.

Here the steps,

We need on SharePoint list and i have created associate list as below.


First we will design html page where we will show a button to get all items in associate list and display in a table. 

Before that we will add one content editor web part to the page. as we know that RESTAPI code will be write in script tags <script></script> and will keep the code in content editor web part.



Page looks like this.


GET ALL ITEMS:


When user click on get associate details, it will fetch the list items and display in a table format. Each row contains update and delete button. Also it will show one common button to add new item.


Here the Output.


ADD AN ITEM:

When user click on "Add Associate", it will show four text box to enter associate id, Name, number and address
It will looks as below when click on "Add associate" button.

Here the code to add new item to list.



After successfully adding new item, the table will update and will show as below.



UPDATE An ITEM:

As previously said, each row have update and delete button. Whenever user click on update button,
it will show four text boxes with the respective item at the bottom of the table.




Now user can update the details and click on "update" button, then it will update the list and refresh the table also.




And when user click on delete button in the table respective item will get delete and refresh the table.




Delete An Item:

When user clicks on delete button, it will delete the respective item from list and update the table.






Find the complete code over here

Saturday, March 21, 2015

SharePoint 2013 Document Library Drag and Drop option not showing in IE

One of new feature in SharePoint 2013 is the ability to drag and drop files into document libraries. This is useful for adding multiple documents to a library and removes the need to open the library in explorer view.


The reason for drag and drop not working and your document library looking like the above screen shot is due to two reasons:
1. You are using Internet Explorer 9 or lower.
2. You don’t have any Office 2013 components installed.

Resolution:

1. This is due to the fact that the drag and drop functionality uses HTML5. Installing Office 2013 will add an ActiveX control to allow you to use this drag and drop functionality in older browsers.
2. If you were to upgrade to IE10 or IE11 the HTML5 would be handled and the drag and drop would be available regardless of whether or not Office 2013 is installed.



Reference link

Monday, March 2, 2015

ISSUE: Save site as template option missing for publishing sites in SharePoint 2013.


Problem: When you browse to  SharePoint Server Site settings page, you discover that the Save site as template option isn't available.

This issue most frequently occurs because the Community Sites or the SharePoint Server Publishing feature is currently enabled or was previously enabled for the affected site. 

SharePoint doesn’t support creating a template from a site where publishing or community features were enabled. This is because the publishing feature creates site elements that are not supported as part of a template, and these elements remain even when the feature is disabled. This also includes templates that were created through SharePoint Designer.





Even when i tried to navigate to “_layouts/savetmpl.aspx”("Save site as template" page), it is throwing following error.

The "Save site as template" action is not supported on this site.



Here the solution:
After searching on net and i came to know that for publishing site "SaveSiteAsTemplate" is disabled.

Now how to enable this option.


Below are the steps to resolve this issue.


1. Open you Team Site in SharePoint Designer 2013.


2. In SharePoint Designer, under Sites tab select "Site Options".





3. Find "SaveSiteAsTemplateEnabled" in Site Properties.





4. Next change this setting to "true".




5. Now in your Publishing site navigate to "http://<site name>/_layouts/15/savetmpl.aspx" and you would see the old Save Site as Template Page as expected.