Saturday, October 5, 2013

"Sign in as Different User" in SharePoint 2013

To get this feature of sign in as different user back, we can follow either permanent or temporary solution:

Permanent Solution for all web applications

1. Locate the following file and open it in a text editor: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx

2. Add the following element before the existing "ID_RequestAccess" element:

<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" Text="<%$Resources:wss,personalactions_loginasdifferentuser%>" Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>" MenuGroupId="100" Sequence="100" UseShortId="true" />

3. Save the file.

One time Temporary Solution 
Append /_layouts/closeconnection.aspx?loginasanotheruser=true after site url in browser's address bar.

Example: http://sp-dev-srv:7000/_layouts/closeconnection.aspx?loginasanotheruser=true

PowerShell Popup

To show a popup message in PowerShell, we need to create an object of wscript.shell and then call popup method with parameters.

Popup Syntax
popup("Message to be displayed",0, "popup window title", button type id + icon style id)

Example
$alert = new-object -comobject wscript.shell
$answer = $alert.popup("Do you want to delete these files?", 0,"Delete Files",4+32)
If ($answer -eq 6) {
  $alert.popup("You answered yes.")
} else {
  $alert.popup("You answered no.")
}

#Button Types 
#0 Show OK button
#1 Show OK and Cancel buttons
#2 Show Abort, Retry, and Ignore buttons
#3 Show Yes, No, and Cancel buttons
#4 Show Yes and No buttons
#5 Show Retry and Cancel buttons

#icon style
#16 Stop Icon
#32 Question Icon
#48 Exclamation Icon
#64 Information Icon

#return values of popup method
OK = 1
Cancel = 2
Abort = 3
Retry = 4
Ignore = 5
Yes = 6
No = 7

Delete All SharePoint List Items Using PowerShell 2010

How to delete all list items from SharePoint list?

Follow the steps to delete all list items from SharePoint List

1. Create new PowerShell (.ps1) file with below script using Notepad

$Url = "http://site-url:5000"
$ListName = "Sales 2013"
$Web = Get-SPWeb $Url
$List = $Web.lists[$ListName]

if($List -eq $null)
{    
  Write-Error "The List cannot be found";return
}

Write-Warning "Deleting all list items from $($ListName)"
$Items = $List.GetItems()
Write-Host "Total Items to be deleted : $($Items.count)"

if($Items.count -gt 0)
{
  $shell = new-object -comobject wscript.shell
  $result = $shell.popup("Total Item to be deleted : $($Items.count) `nDo   you want to continue?",0,"Alert",4+32)

if($result -eq "6")
{
foreach ($item in $Items)
{
  $itemId = $item.ID
  $List.GetItemById($itemId).Delete()
  Write-Host "Deleted list item with id $($itemId)"
}
}
}
$List.Update()
$Web.Dispose()


2. Replace values of parameters $Url and $ListName

3. Save file in server hard drive (Example: D:\PowerShell\Delete-List-Items.ps1)

4. Open "SharePoint 2010 Management Shell" with "Run as administrator"

5. Navigate to the folder where the script  file is stored
    (Example: cd D:\PowerShell)

6. Select file to be executed
    (Example: .\Delete-List-Items.ps1)

7. Press enter and enjoy!!

Monday, September 2, 2013

Server Error in ‘/’ Application. Runtime Error in SharePoint 2010

Whenever you will get this runtime error (Server Error in ‘/’ Application), you need do following changes in web.config file

1. Web Application web.config

Open C:\inetpub\wwwroot\wss\virtualdirectories\<port>” and modify the web.config file

a. In customErrors tag set mode="Off" to "On
b. In SafeMode tag set CallStack="true" to false
c. In Compilation tag Debug="false" to true

2.SharePoint web.config (Need to modify if above changes won't work)
Open SharePoint (2010) root directory or 14 hive – C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS and 
modify the web.config file

a. In customErrors tag set mode="Off" to "On
b. In SafeMode tag set CallStack="true" to false
c. In Compilation tag Debug="false" to true

Wednesday, July 3, 2013

SharePoint Web Id using PowerShell

Get SharePoint Web Id using PowerShell


1. Open SharePoint 2010 management Shell (PowerShell) with administrator privileges

2. Execute following command


$site =  Get-SPSite "http://yoursite"
$web = $site.AllWebs["Web Display Name"]
#For root web
#$web = $site.RootWeb
$web.ID

3. Above script will show unique id of the web

Thursday, June 20, 2013

Update DateTime Field In Event Receiver

Updating DateTime Field In Event Receiver sometimes give error, if we use:
properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now.
ToString(); ;
properties.AfterProperties["ApprovedTimeStamp"] = DateTime.Now.ToShortDateString();

Above statements give error as,
Invalid date/time value. A date/time field contains invalid data. Please check thevalue and try again.


This issue is because, SharePoint date-time field accept values in predefined format.
To overcome this issue, try:
properties.AfterProperties["DueDate"] =
DateTime.Now.ToString("yyyy-MM-ddThh:mm:ssZ");

Tuesday, June 18, 2013

JavaScript to Create Media player In SharePoint 2010

Steps to Create Media player In SharePoint 2010 using JavaScript:

1. Create new page in SharePoint site

2. Get <div> on newly created page

Example: <div id=”videoHolder”></div>

3. If page is inherited from master page, find “PlaceHolderAdditionalPageHead” and insert script tag with source as “_layouts/mediaplayer.js”

Example: <script type="text/javascript" src="_layouts/mediaplayer.js"></script>

4. Have one more script tag with following content:

<script type="text/javascript" >

_spBodyOnLoadFunctionNames.push("CreateMediaPlayer");

function CreateMediaPlayer()
{
    var videoUrl = “/Videos/MyVideo.wmv”; // video URL
    insertVideo(document.getElementById("videoHolder"),videoUrl);
}
function insertVideo(videoHolder,videoURL)
{
    mediaPlayer.createMediaPlayer(videoHolder,videoHolder.id, '400px','266px',
    {
         displayMode:'Inline',

         mediaTitle:’Help Video',
         mediaSource:videoURL,
         previewImageSource:'',
         autoPlay:true,
         loop:true,
         mediaFileExtensions:'wmv;wma;avi;mpg;mp3;',
         silverlightMediaExtensions:'wmv;wma;mp3;'
    });
}
</script>


5. Make sure the 
value of variable "videoUrl" is set correctly.

5. Save the page. That’s it!!!

6. Open the page and see the magic.

Thursday, June 13, 2013

SharePoint Modal Window Using JavaScript

Two ways to open SharePoint Modal Window using JavaScript:

1. Using the DialogOptions class.
var options = SP.UI.$create_DialogOptions();

options.title = "My Dialog Title";
options.width = 400;
options.height = 600;
options.url = "/_layouts/DialogPage.aspx";

SP.UI.ModalDialog.showModalDialog(options);

2. Using a generic object.
var options = {
    title: "My Dialog Title",
    width: 400,
    height: 600,
    url: "/_layouts/DialogPage.aspx" };

SP.UI.ModalDialog.showModalDialog(options);

Ref.: http://msdn.microsoft.com/en-us/library/ff410058(v=office.14).aspx

Wednesday, June 5, 2013

Hide Left Panel/Quick Launch From SharePoint 2010 Pages Using CSS

Hide Left Panel/Quick Launch From SharePoint 2010 Pages using CSS:
1.   Use Simple CSS classes to hide left panel
#s4-leftpanel
{ display:none; }
.s4-ca
{ margin-left:0px; }
2.   For single page level change, add Content Editor web part on the page and inject above script in HTML section of that web part.

For all pages in the site, use this script in master page.

Example:
<style type=”text/css”>
#s4-leftpanel
{ display:none; }
.s4-ca
{ margin-left:0px; }
</style>   

How To Get Worker Process Ids Of Application Pools IIS7 ?

To Get Worker Process Ids Of Application Pools IIS7:
  1.   Open Command Prompt With “Ran as administrator”
  2.   Change directory to “c:\Windows\System32\inetsrv
  3.   Enter “appcmd list wps” to get list of application pools to along with worker process id associated with it
Note: Make sure you have IIS7 installed in your machine to execute this command.
4.   Above command will give you output like:
WP “5057” (applicationPool:wkeyrgsdmaguykwegfk)
WP “6089” (applicationPool:SecurityTokenServiceApplicationPool)

Tuesday, June 4, 2013

Rating Not Reflecting In SharePoint 2010

The following two timer jobs are responsible to calculate and display current rating in SharePoint 2010.
-User Profile Service Application - Social Data Maintenance Job
-User Profile Service Application - Social Rating Synchronization Job

These jobs executes every 1 hour by default. If required those can be executed manually:
1. Open

“Central Administration à Monitoring à Timer Jobs à Review Job Definitions à User Profile Service Application - Social Rating Synchronization Job”

And

“Central Administration à Monitoring à Timer Jobs à Review Job Definitions à User Profile Service Application - Social Rating Maintenance Job”


2. Click “Run Now” or change the “Recurring Schedule” as required.

Friday, May 31, 2013

SharePoint "Download A Copy" from a SP Document Library

Generate a link using below format:
http://spsite/subsite/_layouts/download.aspx?SourceUrl=http://spsite/subsite/shared documents/file.docx

And use this URL in Anchor tag / window.open etc. as per the requirement.

Hope that helps.

Friday, May 17, 2013

Get 14 Hive Path Programmatically In C# ( SharePoint 2010)

Use simple one liner code to get 14 hive path using C#:
string setupPath = SPUtility.GetGenericSetupPath(string.Empty);

Method is included in Utilities namespace:
using Microsoft.SharePoint.Utilities;

Above method will return C:\Program Files\Common files\Microsoft Shared\Web Server Extensions\14

Contact Me or post a comment for any technical help related with SharePoint 2010.

Tuesday, May 7, 2013

Using JavaScript In OnLoad Event Of Body SharePoint 2010

When developing web parts or other SharePoint controls many times we might require to call some functions on body onload event. As web part does not contain body tag we cannot use onload attribute of body tag.

To overcome this drawback, a developer can use an array i.e. _spBodyOnLoadFunctionNames
The only thing we need to do is to pass the function's name using .push method.

Example:
<script language="javascript">
_spBodyOnLoadFunctionNames.push("TestFunction");

function TestFunction() 

   alert("hello"); 

</script> 

We can use above script in master page, aspx page, content editor web part, visual web part as per the need.

Contact Me or post a comment for any technical help related with SharePoint 2010.

Thursday, May 2, 2013

Access The Outbound SMTP Server Address From Code

Use following one liner code to get the Outbound SMTP Server Address:

SPContext.Current.Web.Site.WebApplication.OutboundMailServiceInstance.Server.Address


Contact Me or Post comments for any technical help related with SharePoint 2010.

Monday, March 25, 2013

Use custom favicon in SharePoint 2010 Master Page


Follow the steps to use custom favicon in SharePoint 2010 Master Page
  1. Open SharePoint Designer 2010
  2. Locate master page file in SharePoint Designer 2010
    Note: Default location of master page files: All Filesà_catalogsàmasterpage
  3. Right click on the default master page file
    Note: By default v4.master is default master page file
  4. Check Out master page file and open in Advanced Mode by right clicking to the file
  5. Find “SharePoint:SPShortcutIcon” tag in HEAD section of the content
  6. Replace IconUrl value with custom icon file
    Example:
    <SharePoint:SPShortcutIcon runat="server" IconUrl="/images/custom_icon.ico" />
  7. Save file and check in all the changes
  8. Publish and Approve the changes
Contact Me for any technical help related with SharePoint 2010.

Wednesday, March 20, 2013

Empty Site Collection Recycle Bin using SharePoint 2010 Management Shell (PowerShell)

Follow the steps to Empty Site Collection Recycle Bin using SharePoint 2010 Management Shell (PowerShell):
1.   Open SharePoint 2010 Management Shell with Run as administrator

2.   Modify Site collection Url in following script and execute:

$sitecollectionUrl = "http://site:port/sitecollection"

$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)
write-host("Items to be deleted : " +$siteCollection.RecycleBin.Count.toString())
$now = Get-Date
write-host("Deleting started at " +$now.toString())
$siteCollection.RecycleBin.DeleteAll();
$now = Get-Date
write-host("Deleting completed at " +$now.toString())
$siteCollection.Dispose(); 

Contact Me for any technical help related with SharePoint 2010.

Tuesday, March 19, 2013

Create new SharePoint List Item using SharePoint 2010 Management Shell (PowerShell)

Follow the steps to create new SharePoint List Item using SharePoint 2010 Management Shell (PowerShell):
1.       Open SharePoint 2010 Management Shell with Run as Administrator

2.       Modify and execute following script:

#Web absolute URL where list exists
$webURL = "<http://site:port/site/subsite>" 

#SPList Name where items to be added
$listName = "<List Name>" 

#Get the SPWeb object and save it to a variable
$web = Get-SPWeb $webURL 

#Get the SPList object to retrieve the List
$list = $web.Lists[$listName] 

#Create a new item
$newItem = $list.Items.Add() 

#Add properties to this list item
$newItem["Title"] = "Title Text"
$newItem["Description"] = "Description Text" 

#Update the object so it gets saved to the list
$newItem.Update()

$web.Dispose()

Contact Me for any technical help related with SharePoint 2010.

Monday, March 18, 2013

Determine Site / Site Collection Size (SharePoint 2007 & 2010)


1.   Open SharePoint 2010 Management Shell / Windows Command Prompt with Runas Administrator

2.   Enter below command to access "stsadm.exe" and press enter
cd "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN"
(Replace 14 by 12 for SharePoint 2007)

3.   Type below command and press enter
STSADM.exe -o enumsites -url "<Url of the web application>"
4.   Command will give text output where you can see site/site collection details like:
a.   Url
b.   Ower
c.   Content Database
d.   Storage Used MB
e.   Storage Warning MB
5.   Modify the command with text file path to get output in text file
Example:
STSADM.exe -o enumsites -url "<Url of the web application>" > c:\SiteDetails.txt

Contact Me for any technical help related with SharePoint 2010.

Wednesday, March 6, 2013

Open SharePoint Designer 2010 with Different User

Follow the steps to open SharePoint Designer 2010 with Different User
 

1.   Open windows command prompt by hitting "cmd" in Run 
2.   Enter the below command,
For 64bit, 
runas /profile /user:<domain\username> "c:\program files\microsoft office\office14\spdesign.exe" 
For 32 bit, 
runas /profile /user:<domain\username> "C:\Program Files (x86)\Microsoft Office\Office14\spdesign.exe"

3.   Enter the password of the user when prompted 
4.   SharePoint Designer will get opened with Different User


Contact Me for any technical help related with SharePoint 2010.