Tuesday, 20 December 2011

Listing all the Content Types and Fields with PowerShell in Sharepoint 2010

For many reasons at some point you will need to know how many content types you have and all the fields in a particular content type. I wrote a nice script few weeks ago you can run very easily.

Use PowerGui to run it or just copy/paste this code in a file, save it and run it with the native PowerShell.

	write-host ("...Listing Content Types")
	
	$url=  "http://sp_foundation_g/sites/Documents"
	$site = get-spsite $url 
	
	$web = $site.OpenWeb() 
	
	foreach ($contenttype in $web.ContentTypes)
	{	write-host("##################")
		write-host("Content Type Name:" + $contenttype.Name)
		write-host("Fields:")
		foreach ($field in $contenttype.Fields)
		{
			write-host($field.get_InternalName())
		}
	}
	

Enjoy!

Nice tools to work with Powershell under the Sharepoint 2010 scope.

I am sure that many of you already know these tools, but sometimes it takes me a while to find the stuff on Internet, so I was thinking to pack my favourite ones in one post, this is the result.

PowerGui:
A beautiful GUI to program with PowerShell. It allows you to do everything, it doesn’t eve allow you to modify the user Interface.
Download the software from here, it is FREE! and run this command: Add-PSSnapIn Microsoft.SharePoint.Powershell in PowerGui in order to get the Sharepoint commands.

Windows PowerShell Command Builder:
Developed by Microsoft in Silverlight, it will give you the best overview of command creation for Sharepoint on the net, it is unbeatable, to download it, go here. Check the screenshot!
image

Wednesday, 9 November 2011

“ The specified named connection is either not found in the configuration, not intended to be used with the EntityClient Provider, not valid. “

You will probably get this error when you are trying to use one edmx object from another project, and normally happens with a WCF service or a WinForm Application.

This is the scenario; we have one project where we have the data model (AxxiaDALSP) . In order to make that work we will call that dll (project) from our test harness (TestHarness) project. We are working with .NET 3.5 because we are developing something for Sharepoint and when we call our object we get: “The specified named connection is either not found in the configuration, not intended to be used with the EntityClient Provider, not valid.”.

image
How to sort it?, well it is easy:

  1. Be sure that the App.Config is empty:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    </configuration>

  2. Go to the edmx file and double click.
  3. Remove everything from there.
  4. Right click in the blank area->Update Model From Database. Follow the steps.
  5. Right click in the blank area->Properties->Metadata Artifact Processing:Embed in Output Assembly.
  6. Copy the generate connection string and paste it into your winform App.Config or Web.Config. This is what you should copy:
    <connectionStrings>
      <add name="axxia01Entities" connectionString="metadata=res://*/AxxiaDataModel.csdl|res://*/AxxiaDataModel.ssdl|res://*/AxxiaDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxxmyserverxxx;Initial Catalog=xxmytablexxx;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>

  7. Everything should work now!

Conclusion: This bug can be fixed in many ways, but this is the only one that worked for me. It comes in Visual Studio 2010.