manoj´ssharepointblog

SharePoint Blog


Leave a comment

Download a file from SharePoint using Power Shell

$fromsite = “http://ServerrURL/sites/yoursite”
$fromfile = “documentLibrary/yourfile.xlsx”
$tofile = “c:\test\yourfile.xlsx”
$web = Get-SPWeb $fromsite
$file = $web.GetFile($fromfile)
$filebytes = $file.OpenBinary()
$filestream = New-Object System.IO.FileStream($tofile, “Create”)
$binarywriter = New-Object System.IO.BinaryWriter($filestream)
$binarywriter.write($filebytes)
$binarywriter.Close()

Advertisements


Leave a comment

Creating Search Service Application using PowerShell In SharePoint

It might be necessary at some point to use PowerShell to provision search service applications. Below is the script which can be used for creating a Search Service Application With comments

Below is the Power Shell Script which I used for the creation Search Service Application

$searchapp = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceApplicationName -ErrorAction silentlycontinue
//Check if the SearchService Application Already exists
if($searchapp -eq $null)
{
//For the content Source after the creation of the search service application
$contentSourceURls = “URL1″,”URL2″,”URL3″,”URL4”;
// Name of Application pool
$ManagedMetaDataAppPool =”MySearchServiceApplicationPoolAccount”
$ManagedAccount = Get-SPManagedAccount | select -First 1
// 1. Creating a an application pool for your search service application and throwing the object into a variable called $ app:
$ApplicationPool = Get-SPServiceApplicationPool $ManagedMetaDataAppPool -ErrorAction SilentlyContinue
if ($ApplicationPool -eq $null) {
$ApplicationPool = New-SPServiceApplicationPool -Name $ManagedMetaDataAppPool -Account $ManagedAccount
}
// “2. Creating search Service.”
$searchapp = New-SPEnterpriseSearchServiceApplication -name $SearchServiceApplicationName -applicationpool $ApplicationPool
//Note: Add the -partitioned switch after -name if the search service application will be consumed in a hosted environment.
// “3. Creating Search Service proxy.”
$proxy = New-SPEnterpriseSearchServiceApplicationProxy -name $SearchServiceApplicationName -Uri $searchapp.uri.absoluteURI
$si = Get-SPEnterpriseSearchServiceInstance –local
// “4. Start Services search services for SSI”
Start-SpEnterpriseSearchServiceInstance -identity $si
Set-SPEnterpriseSearchAdministrationComponent –searchapplication $searchapp –searchserviceinstance $si
// “5.Create a new Crawl Topology.”
// By default, a search application created in PowerShell has a crawl topology but is missing the following:
// · crawl component
// · query component
// You cannot add a crawl\query component to the default crawl\query topology because it’s set as active and the property is read // only. The easiest way around this is creating a new crawl topology and new query topology. After creating both, they will be // set as inactive by default. This allows for both crawl components to be added to crawl topology and query component to be added // to newly created query topology. Finally, you can set this new crawl topology to active.
$ct = $searchapp | New-SPEnterpriseSearchCrawlTopology
$csid = $SearchApp.CrawlStores | select id
$CrawlStore = $SearchApp.CrawlStores.item($csid.id)
// “6.Create a new Crawl Component.”
New-SPEnterpriseSearchCrawlComponent -crawltopology $ct -crawldatabase $Crawlstore -searchserviceinstance $SearchServiceInstance
net stop sptimerv4
net start sptimerv4
$done = $false
do
{
$ct | Set-SPEnterpriseSearchCrawlTopology -Active -ErrorVariable $err
if ($ct.State -eq “Active”)
{
$done = $true
}
Start-Sleep -Seconds 10
Write-Host $ct.State
}
until ($done -eq $true)
// “7. Create a new Query Topology.”
$qt = $searchapp | new-spenterprisesearchquerytopology -partitions 1
$p1 = ($qt | get-spenterprisesearchindexpartition)
// “8. Create a Query Component.”
new-spenterprisesearchquerycomponent -indexpartition $p1 -querytopology $qt -searchserviceinstance $si
$PSID = $SearchApp.PropertyStores | Select id
$PropDB = $SearchApp.PropertyStores.Item($PSID.id)
$p1 | set-spenterprisesearchindexpartition -PropertyDatabase $PropDB
$done = $false
do
{
$qt | Set-SPEnterpriseSearchQueryTopology -Active -ErrorVariable $err -ErrorAction SilentlyContinue
if ($qt.State -eq “Active”)
{
$done = $true
}
Start-Sleep -Seconds 10
Write-Host $qt.State
}
until ($done -eq $true)
// “9. Adding the content source urls.”
$contentSource = New-SPEnterpriseSearchCrawlContentSource -Name “My ContentSource” -SearchApplication $searchapp -Type SharePoint -SharePointCrawlBehavior “CrawlSites”
foreach ($contentSourceURl in $contentSourceURls)
{
$contentSource.StartAddresses.Add($($Url.Trim(“/”)+$contentSourceURl))
}
}


Leave a comment

Modify property values of a web part in SharePoint website programmatically using C#

Some times other than reading the values of the property of a webpart we need to update the value of a webpart. When you try to update the property of a webpart it does not get updated. This is due to the fact that the SaveProperties is not set to true.
Continue reading


16 Comments

CREATE INFOPATH FORM WITH LOOKUP FUNCTIONALITY TO SHAREPOINT LIST

This is a guide for setting up an InfoPath form that will fill in other textboxes with data retrieved from a SharePoint list or library, this form will be published to a SharePoint form library in order to provide end users an easy way to fill in a form. This solution is created by using InfoPath 2013 and SharePoint 2013.

Continue reading


8 Comments

jQueryUI’s Autocomplete Function on InfoPath Forms in SharePoint

Recently I worked on a requirement where I need to implement the functionality of JQuery UI´s Auto Complete functionality on a Text box of Browser Based Infopath forms in SharePoint.

We all are familiar with this idea of AutoComplete, if not the actual term. You probably see it in action every single day as you use a search engine. As you type your search term(s), the search engine shows suggestions, probably based on some fairly sophisticated algorithms.
Continue reading