How to avoid page refresh,flickring in postback

It is very very simple to avoid p page refresh in post-back . To get this we just have to use ASP "Update Panel Control" it will not refresh the page again and again on post-back.


Here is an example.

In Default.aspx



<asp:UpdatePanel ID="pnlPageRefresh" runat="server">
        <ContentTemplate>
            <div>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                </asp:DropDownList>
                <br />
                <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"></asp:TextBox>
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
                </asp:RadioButtonList>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
<div>
<asp:Button ID="btnSave" runat="server" Text="Button" />
</div>


After using this your page will not at all refresh again and again on post-back. Your code will work fine but refresh flickering will not occur.

Add Column to Default View Using PowerShell

Recently I had a request from a client to add a custom site collection column to all document libraries. This is pretty easy though the SharePoint UI of course, by creating a custom Site Column in the collection and adding it to the ‘Document’ content type.

However, in doing this the column is not added to the default view for any document libraries. This can be easily done using PowerShell using the script below. This adds the column to the default view in every document library throughout the entire site collection (referenced here).

$site = Get-SPSite “http://sharepoint.com”
$column = “Column”

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

# Get all document libraries
$lists = $_.Lists | where  {$_.BaseType -eq “DocumentLibrary”}

# Loop libraries
for ($i = 0; $i -lt $lists.Count; $i++)
{

try
{

# Get current view
$view = $lists[$i].DefaultView

if($view)
{

# Delete if already exist
while($view.ViewFields.ToStringCollection().Contains($column))
{

$view.ViewFields.delete($column)
$view.Update()

}

# Add column
if(!$view.ViewFields.ToStringCollection().Contains($column))
{

$view.ViewFields.add($column)
$view.Update()

}

}

}
catch [Exception]
{

write-output (”  Error: ” + $_.Exception.ToString())

}

}

}

$site.Dispose()

You can also add views to a view by URL and view name for one specific view or list (a nice tip I found here). Here is another option by using GetViewFromUrl:

$spWeb = Get-SPWeb -Identity "http://mySharePoint"
$spView = $spWeb.GetViewFromUrl("/Lists/MyList/AllItems.aspx")
$spField = $spList.Fields["MyField"]
$spView.ViewFields.Add($spField)
$spView.Update()

You can also try to use SPList object as below:

$spList = Get-SPList -Url "http://mySharePoint/Lists/MyList"
$spView = $spList.Views["All Items"]
$spField = $spList.Fields["MyField"]
$spView.ViewFields.Add($spField)
$spView.Update()

Adding multiple columns to a view can also be done with PowerShell, and even create a new view and set it as the default view. This is really awesome if you want to leave the default ‘All Items’ view in tact, but create a new custom view and set it as default (found here):

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteURL = "http://dev1share"
 $site = Get-SPSite($siteURL)
foreach($web in $site.AllWebs) {
$listCounter = $web.Lists.Count
 for($i=0;$i -le $listCounter;$i++) {
    $list = $web.Lists[$i]
     if($list.BaseType -eq "DocumentLibrary") {
     $newList = $web.Lists.item($list.ID);
  $viewfields = New-Object System.Collections.Specialized.StringCollection
   $viewfields.Add("DocIcon")
   $viewfields.Add("LinkFilename")
   $viewfields.Add("_UIVersionString")
   $viewfields.Add("Modified")
   $viewfields.Add("Created")
   $viewfields.Add("Editor")
   $viewfields.Add("FileSizeDisplay")
  [void]$newList.Views.Add("Detailed", $viewfields, "", 100, $true, $true)
   $newList.Update();
  $view=$newList.Views["Detailed"]
   $view.DefaultView = $true
   $view.Update()
 }
 }
$web.Dispose();
 }
 $site.Dispose();

 

SharePoint PowerShell Create View Based on Existing View

The following PowerShell script crawls the specified lists, copies the fields from the All Items views and creates a new view named "Created By Me" and sets it as default. Tested with SharePoint 2010 but should work with 2013 as well. Tested with list but not with Document Libraries.

I used this script as a base.

$ver = $host | select version

if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 

{

 Add-PSSnapin "Microsoft.SharePoint.PowerShell"

}

 

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

 

$web = Get-SPWeb -Identity "http://portal/sites/Requests"

$lists=$web.Lists["User Request", "Hardware Request",  "Employee Request"]

$SourceView="All Items"

$NewViewName="Created By Me"

$NewViewDefault=$true

 

 

foreach($list in $lists) {

 

 $view = $list.Views[$SourceView]

 $Viewfields = $list.Views[$SourceView].ViewFields.ToStringCollection()

 $viewRowLimit="100"

 $viewPaged=$true

 $viewDefaultView=$NewViewDefault

 

# Setting the Query for the View

 $viewQuery = "<ORDERBY><FIELDREF name="" false="" ascending=""></FIELDREF></ORDERBY><WHERE><EQ><FIELDREF author="" name=""><VALUE type="" integer=""><USERID type="" integer=""></USERID></VALUE></FIELDREF></EQ></WHERE>"

 $viewName = $NewViewName

 

# Finally – Provisioning the View

 $myListView = $list.Views.Add($viewName, $viewFields, $viewQuery, 100, $True, $False, "HTML", $False)

 

# You need to Update the View for changes made to the view

# Updating the List is not enough

 $myListView.DefaultView = $True

 $myListView.Update()

 $list.Update()

}

$web.Dispose()

How to create List using Power shell Script in SharePoint 2013

In this post we are going to see how to create Custom List from Power Shell in SharePoint 2013.

Create a SharePoint Custom List  Student Info with Columns
SNo    -  Number
SName  -  Text
Gender -  Choice
Photo  -  URL

#To which site u want to create the list
$spWeb=Get-SPWeb -Identity http://mySharePoint.ca

#List type or template
$spTemplate = $spWeb.ListTemplates["Custom List"]

#Get all the lists to the listcollection
$spListCollection=$spWeb.Lists

#adding the new list to the list collection
$spListCollection.Add("Studentlist","Studentlist",$spTemplate)

#get the path of subsite and sitecollecion
$path = $spWeb.url.trim()

#get the list to the list object
$spList = $spWeb.GetList("$path/Lists/Studentlist")

#adding the field type(Number) to the list
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Number
$spList.Fields.Add("SNo",$spFieldType,$false)

#adding the field type(Text) to the list
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text
$spList.Fields.Add("SName",$spFieldType,$false)

#adding the field type(choice) to the list
$choices = New-Object System.Collections.Specialized.StringCollection
$choices.Add("Female")
$choices.Add("Male")
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Choice
$spList.Fields.Add("Gender",$spFieldType,$false,$false,$choices)

#adding the field type(url) to the list
$spList.Fields.Add("Photo","URL",$false)

$Views = $spList.Views["All Items"]
$Views.ViewFields.Add("SNo")
$Views.ViewFields.Add("SName")
$Views.ViewFields.Add("Gender")
$Views.ViewFields.Add("Photo")

$Views.Update() - See more at: http://www.dotnetsharepoint.com/2013/06/how-to-create-list-using-power-shell.html#.U9_gPu90y9I

SharePoint 2010: Delete Service Application

Original Post: https://knowledge.zomers.eu/SharePoint/Pages/How-to-remove-a-SharePoint-2010-Service-Application.aspx

It may be necessary to remove one or more Service Applications in SharePoint 2010. It has happened to me quite a few times alread that the Search Service Application got corrupt and needed to be recreated. Unfortunately often this isn't as easy as using the standard delete function in the ribbon. Luckily there are other ways to get it done.

First method - The official way

  1. Open up Central Administration
  2. Click on the link Manage service applications under Application Management

    SP2010RemoveServiceAppCentralAdminLink.png
  3. Click the row with the Service Application you wish to delete so it will be marked in blue. Click on the Delete button in the ribbon to initiate the deletion process. Allow a couple of minutes for it to complete. If it doesn't seem to complete after waiting at most 15 minutes, proceed with method 2 below.

    SP2010RemoveServiceAppDeleteLink.png

Second method - The PowerShell backdoor

  1. If the first method does not work, you can try it using a direct PowerShell command. Open up a PowerShell window on your SharePoint 2010 server.
  2. Type the following line to enable the SharePoint PowerShell AddIn for the current window:

    Add-PSSnapin Microsoft.SharePoint.PowerShell

    SP2010RemoveServiceAppAddPSSnapin.png

  3. Type the following command to list all the Service Applications available on your farm. Look for the one being the Service Application you want to delete and copy its value in the Id column:

    Get-SPServiceApplication

    SP2010RemoveServiceAppGetSPServiceAppId.png
  4. Type the following command to remove the Service Application. Provide the Id retrieved at the previous step behind the Identity parameter:

    Remove-SPServiceApplication -Identity <id>

    SP2010RemoveServiceAppCommand.png
    If this also takes a long time (allow it at most 15 minutes to complete), proceed with method 3 below.

Third method - The dirty way

If the two options above fail, there is stil the dirty way of forcing removal:

  1. Follow steps 1 to 3 from method 2 to retrieve the Id of the Service Application you wish to remove, if you haven't got this Id yet.
  2. Enter the following command to instruct removal of the Service Application. Replace <id> with the Id retrieved at the previous step:

    stsadm -o deleteconfigurationobject -id <id>

    SP2010RemoveServiceAppStsadmCommand.png

    Allow a couple of minutes for this to complete. If also this method seems to be stuck, leave the process running, open up services.msc via the Windows start menu and restart the SharePoint 2010 Timer Windows service. That should get the command to complete after which the Service Application should be gone.

    SP2010RemoveServiceAppTimerService.png
  3.  
Thanks and I hope this helps someone else too.

SharePoint 2010: Update Farm accounts with Get-SPManagedAccount

Sharepoint 2010 is here with powershell integration making it easy to change the passwords for sharepoint managed accounts whose passwords are not set to change automatically when nearing expiration. 

1) Change the password in AD for service account.

2) Update the password for the service accounts in the sharepoint 2010 farm .

Here is a quick run through

Change the password in AD for service account.

I assume  you can log on to a windows 2008 r2 server in domain where service account exists , you have rights to change the password for the service account. I am using a fictitious account  by the name _svc_acct for this scenario

a) After logging into a server in account domain  launch powershell

b ) Load the AD module

import-module activedirectory

c) Assign the account name to a variable

     $account="_svc_acct"

d) set the password ( please note this as we will be using this in the next section)

     Set-ADAccountPassword -Identity $account -OldPassword (ConvertTo-SecureString -AsPlainText  "xxxx" -Force) -NewPassword (ConvertTo-SecureString -AsPlainText "xxxxx" -Force)

e) Check for successful update of the password updation  ( out put should show recent tiem stamp)

Get-ADUser $account -properties * | select PasswordLastSet

For engineers who do not have windows 2008 r2 machines , you can always change password through your normal process.

Update the password for the service accounts in the sharepoint 2010 farm .

 a) Log on to the CA in the Farm, launch powershell.  Assign the new password from step d in the above section to a variable also store the account to a variable

$account="_svc_acct"

$securepassword=convertto-securestring "xxxxx" -asplaintext -force

b) Retrieve the Sp managed account   and pipeline it to the set-spmangedaccount cmdlet

Get-SPManagedAccount Domain\$account | Set-SPManagedAccount -ExistingPassword $securepassword -UseExistingPassword -confirm:$false

Tracing Service failed to create the trace log file at location specified in - SharePoint 2010: No new ULS logs being generated

Problem: Customer discovered that the ULS logs had stopped generating. Within the Logs file there were files but from an old date.

Troubleshooting: I looked in Event viewer and found this:

Tracing Service failed to create the trace log file at location specified in SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\LogDir Error 0x0: The operation completed successfully. . Traces will be written to the following directory: C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\.

Resolution:

  1. In Central Admin go to Monitoring>>Configure diagnostic logging
  2. changed the ‘Path’ value to C:\Temp and then back to D:\SharePoint\Logs or %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\LOGS\, or whatever it was before! (changing it back and forth resolved this problem) 

The Event Log should stop reporting this error!

 

“There were problems searching audience, please contact the system administrator.” in Sharepoint 2010

Had an issue with Audiences in Sharepoint 2010, Kept getting the error “There were problems searching audience, please contact the system administrator.” whenever I tried to add/target an audience in my Sharepoint 2010 in the Top Navigation.

What this error normally/really means is that Sharepoint cannot connect to the User Profile Service Application Proxy (You would get a similar error if your Enterprise search was trying to crawl your user profiles) or the User Profile Synchronization Serive (UPSS), which was my case.

To fix this you need to

  1. Open “Central Administration”
  2. Click “Application Management”
  3. Click “Manage Web Applications”
  4. Find and click on the “Web Application” or “Website” you are getting the error in (in my case ‘sharepoint -80′)
  5. Click “Service Connections” under the “Manage” ribbon
  6. Make sure that “User Profile Service Application” is checked (you may have to change from default to custom to be able to do this). This MIGHT be unchecked if you have recently deleted the default User Profile Service Application and created a new one using a different name, like I did, AND the Connection is NOT set to Default!!
"This worked great. The only other thing you need to do that wasn’t mentioned above is go to services in CA and make sure the user profile service is started.
Hope this helps someone else out there cos this took me 5 hours to figure out!
Dave

Migrate from classic-mode to claims-based authentication (SharePoint Foundation 2010)

Original Post: http://technet.microsoft.com/en-us/library/gg251984(v=office.14).aspx

Convert SharePoint Foundation 2010 Web applications that use classic-mode authentication to use claims-based authentication

Perform the steps in the following procedure to use Windows PowerShell to convert existing Web applications to claims-based authentication.

To convert Web applications to claims-based authentication

  1. Verify that you meet the following minimum requirements: See Add-SPShellAdmin.

  2. On the Start menu, click All Programs.

  3. Click Microsoft SharePoint 2010 Products.

  4. Click SharePoint 2010 Management Shell.

  5. From the Windows PowerShell command prompt, type the following:

    $WebAppName = "http:// yourWebAppUrl"
    $account = "yourDomain\yourUser"
    $wa = get-SPWebApplication $WebAppName
    
    Set-SPwebApplication $wa -AuthenticationProvider (New-SPAuthenticationProvider) -Zone Default
    
    
  6. At the Migration prompt, click Yes to continue.

  7. From the Windows PowerShell command prompt, type the following to set the user as an administrator for the site:

    $account = "yourDomain\yourUser"
    $account = (New-SPClaimsPrincipal -identity $account -identitytype 1).ToEncodedString()
    $zp = $wa.ZonePolicies("Default")
    $p = $zp.Add($account,"PSPolicy")
    $fc=$wa.PolicyRoles.GetSpecialRole("FullControl")
    $p.PolicyRoleBindings.Add($fc)
    $wa.Update()
    
    
  8. From the Windows PowerShell command prompt, type the following to configure the policy to enable the user to have full access:

    $zp = $wa.ZonePolicies("Default")
    $p = $zp.Add($account,"PSPolicy")
    $fc=$wa.PolicyRoles.GetSpecialRole("FullControl")
    $p.PolicyRoleBindings.Add($fc)
    $wa.Update()
    
  9. From the Windows PowerShell command prompt, type the following to perform user migration:

    $wa = get-SPWebApplication $WebAppName
    $wa.MigrateUsers($true)
    
note Note:

We recommend that you use Windows PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

 

Additional migration guidelines

After you perform the steps in the previous procedures, you might experience one or more of the following issues.

  • Users who submit valid credentials might be notified that they do not have permissions. If this occurs, the portalsuperuseraccount property and the portalsuperreaderaccount property of the Web application were probably configured prior to migration. If this is the case, you must update the portalsuperuseraccount property and the portalsuperreaderaccount property to use the new claims-based account name. After migration, you can find the new claims-based account name in the Web application policy for the migrated Web application.

  • If existing alerts are not invoked after migration, you might have to delete and recreate the alerts.

  • If Search crawl does not function after migration, make sure the Search crawl account lists the new converted account name. If the new converted account name is not listed, you must manually create a new policy for the crawl account.