Copy Users to another Site Collection

Hey Folks,

Please find below script to copy users from one site collection to another in SharePoint User Group.


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SourceWebURL = "YourSourceSiteUrl"
$TargetWebURL = "YourTargetedSiteUrl"
$SourceGroupName="YourSourceGroupName"
$TargetGroupName="YourTargetGroupName"

$SourceWeb = Get-SPWeb $SourceWebURL
$TargetWebURL= Get-SPWeb $TargetWebURL

$SourceGroup = $SourceWeb.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $TargetWebURL.groups | where {$_.name -eq $TargetGroupName }

foreach ($user in $SourceGroup.users)
{
$TargetGroup.AddUser($user)
Write-Host "Copied $user from $SourceGroup to $TargetGroup"
}

Happy SharePointing ūüôā

Advertisements

Handle SharePoint large list (throttling)

Hello Folks

Most of the Developers face the throttling issue while bind and load the data from list to gridview. especially in those scenarios when you have thousands or millions of records in list. in order to protect the performance of the farm as a whole. Limits are applied on a per-Web application basis and are typically managed through the Web application settings in Central Admin. but you can handle the throttling issue while fetching the records from large list, i have tested this code on 10,000 records.

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["yourList"];
SPQuery query = new SPQuery();
query.QueryThrottleMode = SPQueryThrottleOption.Override;
SPListItemCollection items = list.GetItems(query);

The SPQueryThrottleOption enumeration has three values: Default, Override, and Strict. If you use the default value, the standard list view threshold applies to all users except local server administrators, who are not bound by either threshold. If you set the query throttle mode to Override, users who have the required permissions in the Web application user policy can query at the higher “auditors and administrators” threshold. Local server administrators remain unbound by either threshold. Finally, if you set the query throttle mode to Strict, this closes down the local server administrator loophole and the standard list view threshold applies to all users.

Hope this Help

Thanks

Happy SharePointing ūüėČ

 

CheckIn and Approve all pages(PowerShell) SharePoint

Hello Folks,

After long time i am writing this blog.  here we gonna talk about checkin and publish all pages at once.

there are lots of ways to check in and approve pages at once. like from Site structure and powershell or you can check in and approve pages one by one from page library. but if you have 100s of  subsites in site collection so those method can be headache and painful for you.  so this script can help you out to checkin and approve all pages from your site collection even you have thousands of subsites in site collection.

 

function PublishAllPages ($url)

{

    $site = Get-SPSite -Identity $url

    #Walk through each Publishing Web and check in every page

    $site | Get-SPWeb -limit all | ForEach-Object {

        #Check to see if site is a publishing site

        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($_)) {

            write-host "Reviewing pages in"$_.Title"site...."

            #Get the Publishing Web and pages within it

            $publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)

            $publishingPages = $publishingWeb.GetPublishingPages()

            foreach ($publishingPage in $publishingPages)

            {

                #Check to ensure the page is checked out, and if so, check it in

                if ($publishingPage.ListItem.File.CheckOutStatus -ne "None")

                {

                    CheckInPage -page $publishingPage -web $_

                }

                else

                {

                    #Notify administrator that the page is already checked in

                    write-host $publishingPage.Title"("$publishingPage.Name") has already been checked in"

                }

                #Check to ensure page is checked in, and is so, approve it

                if ($publishingPage.ListItem.File.CheckOutStatus -eq "None")

                {

                    ApprovePage -page $publishingPage

                }

            }

        }

        else

        {

            #Notify administrator that the site is not a publishing site

            write-host $_.Title"is not a publishing site"

        }

    }

    #Dispose of the site object

    $site.Dispose()

}

function CheckInPage ($page, $web)

{

    #Check to ensure the page is checked out by you, and if so, check it in

    if ($page.ListItem.File.CheckedOutBy.UserLogin -eq $web.CurrentUser.UserLogin)

    {

        $page.CheckIn("Page checked in automatically by PowerShell script")

        write-host $page.Title"("$page.Name") has been checked in"

    }

    else

    {

        write-host $page.Title"("$page.Name") has not been checked in as it is currently checked out to"$page.ListItem.File.CheckedOutBy

    }

}

function ApprovePage ($page)

{

    if($page.ListItem.ListItems.List.EnableModeration)

    {

        #Check to ensure page requires approval, and if so, approve it

        if ($page.ListItem["Approval Status"] -eq 0)

        {

            write-host $page.Title"("$page.Name") is already approved"

        }

        else

        {

            $page.ListItem.File.Approve("Page approved automatically by PowerShell script")

            write-host $page.Title"("$page.Name") has been approved"

        }

    }

    else

    {

        write-host $page.Title"("$page.Name") does not require approval in this site"

    }

}

after running above script run the below command to call above script.

PublishAllPages -url sitecollectionurl

Thanks to  for this script!

Hope this help.

Happy SharePointing ūüėČ

The EXECUTE permission was denied on the object proc_MSS_GetTopology’, database ‘Search_Service_Application_DB

Hello Folks,

when i got back to work in the morning i saw my search service was not working and throwing the error.

The EXECUTE permission was denied on the object ‘proc_MSS_GetTopology’, database Search_Service_Application_DB ¬†{GUID} ‚ÄĚ ¬†this was caused due to the fact my new farm account didn‚Äôt have the‚ÄúSPSearchDBAdmin‚ÄĚ ¬†role assigned under the Security > Users ¬†> ‚ÄúSP farm Account‚ÄĚ ¬†on Search_Service_Application_DB¬† database (SQL Server Management Studio) other databases related to SharePoint Search service.¬† Once this was resolved my ‚ÄúSearch Service Application: Search Administration‚ÄĚ page displayed and I could create crawls. ¬†you can follow below image for assigning the role of¬†SPSearchDBAdmin.

423350

 

Thanks

Hope this Help.

Happy SharePointing ūüôā

 

 

User Profile Synchronization Service SP2013 stuck on starting after upgrade from SP2010 to SP2013

Hello Folks,

I am in the process of upgrading our SharePoint Farm from 2010 to 2013. recently i have upgraded my User Profile Service and had trouble starting the UPS Synchronization Service which I spent hours trying to solve this issue. The UPS service application requires an encryption key that is stored separately from the database and is needed if you want to upgrade the User Profile Sync database.

steps to solve this issue.

Export the key from your SP2010 Farm:

just run the command prompt and execute this command.

%Program Files%Microsoft Office Servers14.0Synchronization ServiceBinmiiskmu.exe

Once you run this command Follow the prompt with your Farm Account credentials.

 

1

Copy the key file to the 2013 Farm

Import the Encryption Key on the SP2013 Farm:

Open a command Prompt from this location:

%Program Files%Microsoft Office Servers15.0Synchronization ServiceBin

Type the following: (Yes including the GUID)

miiskmu.exe /i YourFilePathwithFilename  {0E19E162-827E-4077-82D4-E6ABD531636E}

You should receive a message stating that the import was successful.

Start the UPS Sync Service

Starting the Service through CA then worked for me.

 

Hope this Help ūüôā

Happy SharePointing

Search Application Topology

hey folks,

just recently i have implemented Search topology  with PowerShell so i thought i should share with you. there is no more UI options to set the search topology on different servers as we used to do in SharePoint2010, in SharePoint2013 you have to do it with PowerShell cmdlet , my current  scenario is that i have 3 servers and i have divided all component on these servers as you can see in the picture of After movement.

1 App Server

2 Web Front-end Servers.

SharePoint farm environment usually the Application Server will host all the Services including the Search Application services. The Search Application consists of several Search components like

  • Admin
  • Crawler
  • Content Processing
  • Analytics processing
  • Query Processing
  • Index

   Before Movement

Untitled

   After Movement 

search topology

 

below is the PowerShell cmdlet through these commands you can move the search Component.


$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone ‚ÄďSearchTopology $active

$Srv2 = Get-SPEnterpriseSearchServiceInstance -Identity "Server Name Here"
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $Srv2
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $clone -SearchServiceInstance $Srv2
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $Srv2
New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $Srv2

Start-SPEnterpriseSearchServiceInstance -Identity $Srv2
Set-SPEnterpriseSearchTopology -Identity $clone
‚ÄĒ‚ÄĒ‚ÄĒ‚ÄĒ‚ÄĒ-
<em>Clone again to remove original</em>

$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone ‚ÄďSearchTopology $active

Get-SPEnterpriseSearchComponent -SearchTopology $clone¬† ‚ÄĒ to get the component id for the subsequent commands

Remove-SPEnterpriseSearchComponent -Identity  <strong><span style="text-decoration: underline;">COMPID</span></strong> -SearchTopology $clone -confirm:$false
Set-SPEnterpriseSearchTopology -Identity $clone

‚ÄĒ‚Äď

COMPID is the component id of the search component to be removed. You can get all component running on the server by using the command

Get-SPEnterpriseSearchComponent -SearchTopology $clone

 

thanks

Hope this help

Happy sharePointing ūüėČ

 

post back issue after file download from SharePoint

hello Geeks,

i was facing ¬†issue to download the file from SharePoint¬†¬†after I download this file, I can’t click on other buttons even the same download button does not work. ¬†after little search i found some information regarding this issue,¬†SharePoint registers a JavaScript “on submit” handler. In this handler the global variable _spFormOnSubmitCalled is set to true. SharePoint uses this variable to check if a submit was executed and prevents any further submits. Since your “download postback” does not refresh the page this variable remains true. With the effect that all other buttons stop working. In SharePoint 2013 ¬†there is a function for resetting _spFormOnSubmitCalled to false already so no need to write your own.

here is my code


 SPList list = webObj.Lists["Documents"];
 SPFile file = list.RootFolder.Files["your pdf file url"];
 Response.ContentType = "Application/pdf";
 Response.AppendHeader("content-disposition", "attachment; filename=" + file);
 Response.Clear();
 Response.Flush();
 Response.End();

 

after writing this code just add the below line to your client side code.

 

<asp:LinkButton ID="lnk" runat="server" OnClick="lnk_Click" Text="<%$ Resources:Portal,DonwloadText %>" CausesValidation="false" OnClientClick="javascript:_spResetFormOnSubmitCalledFlag()"></asp:LinkButton>    

 

Hope this help

Regards

 

 

 

Youtube Integration with SharePoint

Hey Geeks

after long time i am writing this post due to busy schedule. recently i got the opportunity to integrate SharePoint with YouTube i had the requirement to Develop the Videos gallery control and videos should be fetch from YouTube channel.  here are the steps.

first you need to register these three DLLs in your solution in Package.Package file(you can download these DLLs from MyOneDriveShareFiles) then Let‚Äôs create a class to represent YouTube video on our control. The object of this class is a video that has properties:¬†VideoId, Title, PublishDate, VideoDuration.¬† these properties will help us to show the publishing date of the video, Title of the video, and duration of the video, …ETC..there are lots of other properties in the dlls that can help you to more customize the functionality. if you want to make webpart configurable so you need to create webpart properties.

To use all possibilities that YouTube Data API offered, you need to get Developer Key.  Developer key uniquely identifies an application that will interact with the YouTube service. You can get it Here

string YOUTUBE_CHANNEL –> WebPart Property for YouTube channel name

string YOUTUBE_DEVELOPER_KEY –> WebPart Property for YouTube developer Key(Optional)

 



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Client;
using Google.YouTube;

namespace AlQasmia.Utility_Functions
{
    public class YouTubeVideoObject
    {
        public string VideoId { get; set; }
        public string Title { get; set; }
        public string PublishDate { get; set; }
        public string VideoDuration { get; set; }
    }
    public class YouTubeVideoHelper
    {
       // const string YOUTUBE_CHANNEL = "BobinaMusic";
        //const string YOUTUBE_DEVELOPER_KEY = "AI39si6JqO_f2b_JWSV3QUbcwg5S-1RJ4-kiieosBZy9r1ORkCAv7BT5tLp579Tzmly8rvOVm3Jyueq3ZVqUNt1blS4DcoVppA";

        public static YouTubeVideoObject[] GetVideos(string YOUTUBE_CHANNEL, string YOUTUBE_DEVELOPER_KEY)
        {
           
                YouTubeRequestSettings settings = new YouTubeRequestSettings("Channel", YOUTUBE_DEVELOPER_KEY);
                YouTubeRequest request = new YouTubeRequest(settings);

                string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?orderby=published", YOUTUBE_CHANNEL);
                Feed videoFeed = request.Get(new Uri(feedUrl));

                return (from video in videoFeed.Entries
                        select new YouTubeVideoObject() { VideoId = video.VideoId, Title = video.Title, PublishDate = video.YouTubeEntry.Published.Date.ToShortDateString(), VideoDuration = video.Media.Duration.Seconds}).ToArray();
           
           
        }
    }
}


Now its time to bind videos with Repeater control. you can use grid as well.

<asp:Repeater ID="VideosRepeater" runat="server">
    <ItemTemplate>
    
             
Publish Date:<%# Eval(“PublishDate”) %> Duration:<%# Eval(“VideoDuration”)%> (Seconds)
    </div>
    </ItemTemplate>
    <SeparatorTemplate>
      <br />
    </SeparatorTemplate>
    </asp:Repeater>
    <div class="button">
    
    <asp:ImageButton ID="ImgBtnPrev" runat="server" CssClass="button" OnClick="LnkBtnPrev" ImageUrl="/_layouts/images/prev.png" />
    <asp:ImageButton ID="ImgBtnNext" runat="server" CssClass="button" OnClick="LnkBtnNext" ImageUrl="/_layouts/images/next.png" />

Below you can find the Repeater Control Code.


 public YouTubeChannel ParentWebPart
        {
            get;
            set;
        }

        public int PagNum
        {
            get
            {
                if (ViewState["PagNum"] != null)
                {
                    return Convert.ToInt32(ViewState["PagNum"]);
                }
                else
                {
                    return 0;
                }

            }
            set
            {
                ViewState["PagNum"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {

                    YouTubeVideos();
                }
            }
            catch (Exception ex)
            {

                ex.ToString();
            }
           

        }


        public void YouTubeVideos()
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate
                {

                    int cnt;


                    YouTubeVideoObject[] arr1 = YouTubeVideoHelper.GetVideos(ParentWebPart.youTubeChannelName, ParentWebPart.DeveloperKey);

                    DataTable dt = new DataTable();
                    dt.Columns.Add("Title");
                    dt.Columns.Add("VideoId");
                    dt.Columns.Add("VideoDuration");
                    dt.Columns.Add("PublishDate");
                    for (int i = 0; i < arr1.Length; i++)
                    {
                        DataRow row = dt.NewRow();
                        var VidObj = arr1[i];
                        row["Title"] = VidObj.Title;
                        row["VideoId"] = VidObj.VideoId;
                        row["VideoDuration"] = VidObj.VideoDuration;
                        row["PublishDate"] = VidObj.PublishDate;
                        dt.Rows.Add(row);
                    }

                 
                    PagedDataSource pagedata = new PagedDataSource();
                    DataTable dt2 = new DataTable();
                    DataSet ds = new DataSet();

                
                    ds.Tables.Add(dt);
                    cnt = ds.Tables[0].Rows.Count;
                    cnt = ds.Tables[0].Rows.Count;

                    pagedata.DataSource = ds.Tables[0].DefaultView;
                    pagedata.AllowPaging = true;
                    pagedata.PageSize = 10;
                    pagedata.CurrentPageIndex = PagNum;

                    int vcnt = cnt / pagedata.PageSize;
                    if (PagNum < 1)
                      
                        ImgBtnPrev.Visible = false;
                    else if (PagNum > 0)
                      
                        ImgBtnPrev.Visible = true;
                    if (PagNum == vcnt)
                        
                        ImgBtnNext.Visible = false;
                    if (PagNum < vcnt)
                      
                        ImgBtnNext.Visible = true;




                    VideosRepeater.DataSource = pagedata;
                    VideosRepeater.DataBind();





                  
                });
        
            }
            catch (Exception ex)
            {

                ex.ToString();
            }
            
        
        }


        protected void LnkBtnPrev(object sender, EventArgs e)
        {
            PagNum -= 1;
            YouTubeVideos();


        }
        protected void LnkBtnNext(object sender, EventArgs e)
        {
            PagNum += 1;
            YouTubeVideos();
        }

 

These are the Snaps.

YouTubeWP

 

WPProperties

once you deploy the solution just go and configure the webpart properties(if you have) put the channel name and developer Key(if you have) and save it. that’s it

 

Thanks and Have a good day

Happy SharePointing ūüėČ

Remove Extra Space Around the Web Part In SharePoint 2013

Hey Folks,

An extra padding of 20 pixel is included by default in SharePoint 2013 for every webpart. so this issue can be resolve and you can remove extra space around the webpart by this CSS.

 <style type="text/css">

     .ms-webpartPage-root {
         border-spacing: 0px !important;
     }
       .ms-webpartzone-cell {
         margin: 0px !important;
     }
 </style>

 

Happy SharePointing ūüėČ

SharePoinT 2013 Work Management Service : ERROR –> SORRY, WE‚ÄôRE HAVING TROUBLE REFRESHING YOUR TASKS. CONTACT YOUR ADMINISTRATOR IF YOU CONTINUE TO HAVE PROBLEMS

Hey Folks,

Problem 

i was working on work management service / Task management suddenly user came to me and asked some help regarding task syncing problem. User created a task and assign to another user ¬†but task was not showing in MyTask section in UserProfile ¬†and it was throwing error¬†“Sorry, we‚Äôre having trouble refreshing your tasks. Contact your administrator if you continue to have problems”.

 

012714_0720_sharepoint21

 

Solution :  need to check all these points

  • Does a Work Management Service Application exist?
    You can check this if you open the SharePoint 2013 Management Shell and type, this will show you list of Services
 
 Get-SPServiceApplication.  
  • If it does not exist, you have to create one. This can be done via Central Administration or Poweshell.
  • Set the Service Application Pool in a variable.
$SvcAppPool= Get-SPServiceApplicationPool "SvcAppPool"
  • Create the Service Application and assign it to the Application Pool.
 $SvcApp = New-SPWorkManagementServiceApplication -ApplicationPool $SvcAppPool -Name  "WorkManagementServiceApplication"
  • ¬† ¬† ¬†¬†Verify the Service Application.
 
Get-SPServiceApplication | Select Name
  • Now is the Work Management Service running. Check this in the Central Administration -> Manage Services on Server
  • Does an User Profile Service Application exist and is it running?
  • Has the service account under which the Work Management Service is running Full Control permissions to the User Profile Service Application? (Central Administration -> Manage Services and ¬†mark the User Profile Service Application¬†√†¬†click on Permissions in the Ribbon¬†√†¬†grant the service account Full Control).
  • you can check ¬†which service account running the app pool using PowerShell. This script will show you Service account.
$sa = Get-SPServiceApplication | where {$_.DisplayName ‚Äďmatch "WorkManagementServiceApplication"}¬†
$sa.ApplicationPool

after these steps IISRESET and check your Profile Task Section MyTask.

I Hope this Help you.

Happy SharePointing ūüėČ