Filter Major and Minor Versions

Overview of what we are going to do:
Create a Library.
Enable versioning.
Create a new View named Major.
Using SharePoint Designer, convert the Major View to an XSLT Data View.
Apply filtering to the Data View using the Approval Status field = Approved.
Save.
Using the same steps as above, create another View named Minor, and apply a filter for Draft.
Done.

Create a Document Library (I named my MajorMinor) and enable Versioning (Site Settings –> Versioning –> Create major and minor).

Create a new View and name it Major.

Once you have created your new Library, open SharePoint Designer, and open your site.

(File –> Open Site.. )

Now, navigate to your Library, open the Forms folder, and then open the Major.aspx page.

Once the page opens, right click on the Web Part and select Convert to XSLT Data View.

Right click in the Version field –> select Insert –> Column to the Right.

Now look in your Data Source Details Task Pane and locate the Approval Status field.  (If you don’t see the Data Source Details Task Pane, you will want to activate it from the Task Panes menu at the top of your screen)

Once you have located the Approval Status field, drag it into a cell of the column you just added to your Data View.

Now we are going to filter the Data View using our new field.

Click on the Web Part, select the little box in the top right corner of the Web Part, and then select Filter.

Click on Filter, once the Filter Criteria box opens, click on Click here to add a new clause….

From Field Name select Approval Status, Comparison should be Equals, Value is Approved, click Ok to apply the filter.

Save your page (click yes when the warning box opens).

Go back to your browser and refresh the page.  To test your changes, edit and save a document.

Now, to create your Minor View, use the same step shown above, but your filtered value would be Draft.

*NOTE*
1. If your Library has a Workflow attached, you will need to take into account the other Approval Statuses (Pending, Rejected, …)
2. You don’t need to add a new column to the Data View to use the filtering.  You could simply apply the filter without adding the column.

PowerShell Query Webpage SharePoint

Using PowerShell, I was looking for a way to query / search a webpage for a string / variable. If the string was found, do something.

When trying to access a SharePoint page, I needed to use the UseDefaultCredentials = $true function, otherwise I was seeing random errors.

Error example:
The remote server returned an error: (401) Unauthorized.
$web = New-Object System.Net.WebClient
$web.UseDefaultCredentials = $true

If ($web.DownloadString(“http://www.yoursite.com/taco.aspx”)| select-string “Taco”)
{
Write-Host “True”
}
Else
{
Write-Host “False”
}

Get Crawl Status Using Powershell

{Edit} I’ve found another way of doing this{/}

Way One:

I needed a way of knowing when a crawl status was set to paused.  Using a combination of Windows Task, Powershell, SharePoint List, and Workflow I was able to come up with a solution.

Process: Windows Task runs every hour (on the server with Central Administration).  This Task runs my Powershell command.  The command checks all my Content Sources for a crawl status of paused. If the status is paused, the command will write an Item to a SharePoint List.  Associated Workflow on the List then sends me an email.

Link to the completed Powershell command: Powershell Crawl Status (you will need to open the file and save it with a .ps1 extension.)

[void] [System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

[void] [System.Reflection.Assembly]::Load("Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

[void] [System.Reflection.Assembly]::Load("Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

$SITEURL = "http://win-severname"

$spsite = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
$serverContext = [Microsoft.Office.Server.ServerContext]::Default
$context = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($serverContext)
$sspcontent = new-object Microsoft.Office.Server.Search.Administration.Content($context)
$sspContentSources = $sspcontent.ContentSources

[int]$count

$count=0

foreach ($cs in $sspContentSources)

{
if ($cs.CrawlStatus -eq [Microsoft.Office.Server.Search.Administration.CrawlStatus]::Paused)
{

$count++

}
}

if ($count -gt 0)

{

$spweb = $spsite.OpenWeb()
$splist = $spweb.Lists["ListName"];
$items=$splist.get_items() | where { $_.Title -like '*' }

if ($splist.ItemCount -gt 0)
{
$items | % { $_.Delete() }
}
$newItem = $splist.Items.Add()
$newItem["Title"] = "NewItem"
$newItem.Update()

$spweb.Dispose()
$spsite.Dispose()


}

——————————

How to run a Powershell command from a Scheduled Task.

To run a Powershell command you will need to do the following.

1.In the Actions tab:

a.Click New. The New Action dialog box appears.

2.In Settings, in Program/Script, type:

powershell.exe

3.In Add arguments, type the following:

-command “C:\Powershell Crawl Status.ps1”

4.Click OK.

http://technet.microsoft.com/en-us/library/ee649304(WS.10).aspx

Way Two and the EASY way:


$web = New-Object System.Net.WebClient
$web.UseDefaultCredentials = $true

If ($web.DownloadString(“http://craigslistSpam/ssp/admin/_layouts/listcontentsources.aspx”)| select-string “Paused” -CaseSensitive)
{
$emailFrom = "me@craigslistSpam.com"
$emailTo = "you@craigslistSpam.com"
$subject = "testing"
$body = "test email"
$smtpServer = "this can be found in Outlook"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}

 

 

 

Powershell delete items in a list or library

There might be a better way to accomplish this… but for now this works.  Just needed a way to delete all the items in a list.

[System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$spsite = New-Object -TypeName “Microsoft.SharePoint.SPSite” -ArgumentList http://win-vm3$spweb = $spsite.OpenWeb()

$splist = $spweb.Lists[“NameofList”]

$items=$splist.get_items() | where { $_.Title -like ‘*’ }
$items | % { $_.Delete() }

$spweb.Dispose()

$spsite.Dispose()

 

no symbols have been loaded in the document

Fixed.

Windows 7, Visual Studio 2010, SharePoint 2010 installed on desktop.

In Visual Studio 2010 I was not able to set a breakpoint and was shown the error no symbols have been loaded in the document.

?Fix?

Created a new project, but this time I selected to sandbox option.  Even when a breakpoint was set I would still see the error.  Set a breakpoint on my code, clicked Start Debugging (green button), and sure as SH1T, the code stopped on my breakpoint.

failed to create the configuration database

Trying to install SharePoint 2010 on Window 7 and ran into this error.
First, I was using this script to install SharePoint 2010 on my Win7 box.

http://gallery.technet.microsoft.com/scriptcenter/a88cad83-f595-4487-940e-f678ce47eb5f

(make sure you take a look at the Discussions tab.  Ran into a few issues but quickly found solutions on there.

After this, I then hit the failed to create the configuration database error when trying to run the wizard.

Onto another site….

This site outlined all the prerequisiutes needed for a SharePoint 2010 install.

http://blogs.msdn.com/opal/archive/2009/10/25/sharepoint-2010-pre-requisites-download-links.aspx

Not 100% sure what I missed, but I download / installed each of these again.

FIXED!!!