Tuesday, August 7, 2018

Discussion List Reply Link in SharePoint 2013 and Online

Initially it was possible to achieve this using calculated column and concatenate anchor tag and generate a link. However after latest CU release, this is not possible anymore.
Following steps will help you to create a hyperlink column for discussion reply link in SharePoint 2013 or Online. Also it will help you to create a normal calculated hyperlink column in SharePoint 2013 and Online.


1. Below snap in about Discussion list default view and you are targeting to create highlighted link.

2. Create new Single link text Calculated column and add it in Discussion content type.
PN: Select Do not add it in All Content Types while creating a column.


3. Create a simple list view and make sure it consists your new calculated column.


4. Now on the list view page, add new Script Editor or Content Editor webpart.


5. Insert following script to the webpart.


<script>
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
  Templates: {
        Fields: {

          //Replace "ReplyLink" with Calculated column name
           'ReplyLink': {'View':function(ctx) {
                  var url = String.format('{0}/Flat.aspx?RootFolder={1}/{2}', ctx.listUrlDir, ctx.listUrlDir,ctx.CurrentItem.Title);
                  return String.format('<a href="{0}" onclick="EditItem2(event, \'{0}\');return false;">{1}</a>', url, "Bid for the Job");
           }}
       }
  }
});
</script>




6. Save the page and you can access the link in Calculated column.


PN: Whenever you want such functionality, you need to add new webpart on list view page and insert the same script.

Friday, June 16, 2017

PowerShell to Add Data Row-wise to CSV File

Execute following script to insert data in new or existing CSV file.

$FilePath = "D:\Data\FileName,csv"
#Add Title Row
$Row = "Full Name,Age,Gender"
Add-Content ($Row) -Path $FilePath

#Add Data Row
$Name = "Prashant"
$Age = "29"
$Gender = "Male"
$Row = $Name + "," + $Age + "," + $Gender
Add-Content ($Row) -Path $FilePath

Create New Content Database Using SharePoint PowerShell

Execute following script to create new content database using SharePoint PowerShell. You can run this script on any WFE or APP server.

add-pssnapin Microsoft.SharePoint.PowerShell

#Set following parameters
$WebsiteName = "Test Site"
$DbServer = "SQLServer"
$WebAppUrl = "http://webapplink"
$DBName = "WSS_Content_" + $WebsiteName
$MaxSiteCount = 1 

$WarningSiteCount = 0

#Create new content database
New-SPContentDatabase -Name $DBName -DatabaseServer $DbServer -WebApplication $WebAppUrl -MaxSiteCount $MaxSiteCount -WarningSiteCount $WarningSiteCount -ErrorAction Stop

Create Site Collection in New Content Database in SharePoint 2010 / 2013

If you have a requirement where you need to Create a Site Collection in New Content Database, refer following PowerShell Script:

add-pssnapin Microsoft.SharePoint.PowerShell
$url = "http://sitecollection_link"
$ContentDatabase = "Content_DB_Name"
$WebsiteName = "New Site Collection Title"
$WebsiteDesc = "New Site Collection Description"
$Template = "STS#0" #It is for team site (use STS#1 for blank site)
$PrimaryLogin = "Domain\username1"
$SecondaryLogin = "Domain\username2"

New-SPSite -Url $url –ContentDatabase $ContentDatabase -Name $WebsiteName –Description $WebsiteDesc  -Template $Template -OwnerAlias $PrimaryLogin -SecondaryOwnerAlias $SecondaryLogin



Following script will create new content database and create site collection in newly created database. It is with parameters and also handles errors, so looks little longer :P


add-pssnapin Microsoft.SharePoint.PowerShell

#Set following parameters
$WebsiteName = "Test Site"

#Verify following parameters
$DbServer = "SQLServer"
$WebAppUrl = "http://webapplink"
#Uncomment if you are using managed path
#$ManagedPath = "path"
$DBName = "WSS_Content_" + $WebsiteName
$PrimaryLogin = "Domain\UserName"
$SecondaryLogin = "Domain\UserName"
$MaxSiteCount = 1
$WarningSiteCount = 0
$ContentDatabase = $null

#Create new content database
try
{
    $ContentDatabase = Get-SPContentDatabase $DBName -ErrorAction ignore
    if($ContentDatabase -eq $null)
    {
        New-SPContentDatabase -Name $DBName -DatabaseServer $DbServer -WebApplication $WebAppUrl -MaxSiteCount $MaxSiteCount -WarningSiteCount $WarningSiteCount -ErrorAction Stop
        Write-Host "Database Created Successfully" -ForegroundColor Green
        $ContentDatabase = Get-SPContentDatabase $DBName       
    }
    else
    {
        Write-Host "Database already exist." -ForegroundColor Red
    }


    #Set Parameters
    $url = $WebAppUrl + "/sites/" +$WebsiteName
    #Uncomment if you are using managed path
    #$url = $WebAppUrl + "/" + $ManagedPath + "/" +$WebsiteName
    $WebsiteDesc = "FieldDocs for year " +$WebsiteName
    $Template = "STS#1"

    #Create new site collection
    try
    {
        $site= $null
        $site = Get-SPSite $url -ErrorAction ignore   
       
        if($site -eq $null)
        {
            New-SPSite -Url $url –ContentDatabase $ContentDatabase -Name $WebsiteName –Description $WebsiteDesc  -Template $Template -OwnerAlias $PrimaryLogin -SecondaryOwnerAlias $SecondaryLogin -ErrorAction Stop
            Write-Host "Site Collection Created Successfully" -ForegroundColor Green
        }
        else
        {
            Write-Host "Site Collection already exist." -ForegroundColor Red
            $site.Dispose()
        }       
    }
    catch
    {
        Write-Host "Error in site collection creation" -ForegroundColor Red
    }
}
catch
{
    Write-Host "Error in database creation" -ForegroundColor Red
}


Friday, January 3, 2014

How To Use TODAY Function In SharePoint Calculated Field

How To Use TODAY Function In SharePoint Calculated Field?

SharePoint throws an error when you try to use functions like "Today" and "Me" in Calculated Field.

Calculated columns cannot contain volatile functions like Today and Me.

To overcome this issue follow below steps:
1. Create new column named "Today" with any datatype(Single Line Text)


2. Now Create calculated field with TODAY column in formula
Example: =DATEDIF([Start Date], [Today], "d")

3. If you check the columns values now, it will show something like #num!. Ignore it.

4. Now delete column "Today". That's it and check values. It will show corrects output that is date difference between Start Date and Today.

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