another technical blog...technically

Wednesday, March 20, 2013

Embarrassing stories: Visual Studio toolbox shows only General and HTML Tabs

My boss said "Varro, don't dare to use layouts folder or the custom form will be available to the farm, that's not good", so yesterday i tried to create an application page and deploy it using a module. So, when you create an application page in a SharePoint project, Visual Studio automatically  creates the layouts mapped folder and puts the .aspx file there.
After that you can easily drag and drop the aspx file in the module and continue to work the file under the module itself... theorically.
When i dragged the page into the module, only HTML and General tabs were available on the ToolBox panel, and the ASP and SharePoint elements inserted in the page were marked as unexisting in the code behind.
The problem
I started looking around for a possible solution on the web (moreover i was working on a customer VM used by other people, so don't know what happened on this VM) and tried almost everything.
After a hour i clicked on View Markup and... magically the problem solved. I tested the whole process on a new solution on my local machine and i haven't met the same problem.
The solution
The proof
Morality is: if you have this issue, before risking to waste time trying everything, try this "trick".

Tuesday, March 5, 2013

Get site content types and site columns using PowerShell

Lately i'm working to a feasibility study for a intranet migration from SharePoint 2010 to SharePoint 2013.
During this project, i needed to know what are content types and fields were involved in the 2010 custom solution, in order to map them in SharePoint 2013 ones.
My boss asked me to do this A.S.A.P., so i developed a powershell script capable of retrieving these data and put them in CSV files, so i can import them with excel and do further analysis.
The script output is a set of three CSV files:
  1. Site content types
  2. Site columns
  3. Mapping between content types and fields
Here is the code for PowersShell 3.0:
##
## 20130214, from Varro with love
##

Add-PSSnapin Microsoft.SharePoint.PowerShell

## Variables
$WEB_APPLICATION_URL = "http://teamsite"
$CTS_FILE_PATH = "c:\Users\Administrator\Desktop\2013_TeamSite_ContentTypes.csv"
$FIELDS_FILE_PATH = "c:\Users\Administrator\Desktop\2013_TeamSite_Fields.csv"
$CT_FIELDS_FILE_PATH = "c:\Users\Administrator\Desktop\2013_TeamSite_CTs_And_Fields.csv"


## Initialization
echo "Initializing variables"
'"CT Name","CT Description","CT ID","CT Group","CT Parent ID"' | Out-File $CTS_FILE_PATH;
'"Field Title","Field Description","Field Internal Name","Field ID","Field Group","Field Type"' | Out-File $FIELDS_FILE_PATH;
'"CT Name","Field Title","CT ID","Field ID"' | Out-File $CT_FIELDS_FILE_PATH;

$AllContentTypes = @();
$AllFields = @();


## Go with the code
echo "Entering web application $WEB_APPLICATION_URL" 

$webApplication = Get-SPWebApplication -identity $WEB_APPLICATION_URL

ForEach ($siteCollection in $webApplication.Sites)
{
    ForEach($subSite in $siteCollection.AllWebs)
    {
        $subsiteUrl = $subsite.Url;

        echo "Extracting info from $subSiteUrl";

        $contentTypes = $subSite.ContentTypes;

        ForEach ($contentType in $contentTypes)
        {
            If (!$AllContentTypes.Contains($contentType.Id))
            {
                $AllContentTypes += $contentType.Id;

                # Let's write on Content types CSV
                '"' + $contentType.Name + '","' + $contentType.Description + '","' + $contentType.Id + '","' + $contentType.Group + '","' + $contentType.Parent.Id + '"' | Out-File $CTS_FILE_PATH -Append
           
                ForEach ($field in $contentType.Fields)
                {
                    If (!$AllFields.Contains($field.Id))
                    {
                        $AllFields += $field.Id;

                         # Let's write on Fields CSV
                        '"' + $field.Title + '","' + $field.Description + '","' + $field.Id + '","' + $field.Group + '","' + $field.Type + '","' | Out-File $FIELDS_FILE_PATH -Append;
                    }

                    '"' + $contentType.Name + '","' + $field.Title + '","' + $contentType.Id + '","' + $field.Id + '","' | Out-File $CT_FIELDS_FILE_PATH -Append;
                }
            }
        }
    }
}

echo "See you space cowboy";
If you need to run this script in PowerShell 2.0, you just need to change these rows
If (!$AllContentTypes.Contains($contentType.Id))
...
   If (!$AllFields.Contains($field.Id))
with these ones:
$alreadyInCT = $AllContentTypes -contains $contentType.Id;
If (!$alreadyInCT)
...         
   $alreadyInFields = $AllFields -contains $field.Id;               
   If (!$alreadyInFields)
Please feel free to reuse, comment and share.
Share:

Me, myself and I

My Photo
I'm just another IT guy sharing his knowledge with all of you out there.
Wanna know more?