Sometimes the site content type ID is needed for development.
Go to Site Settings -> Site Content Type -> Content Type,
The content type ID is in the URL.
In Powershell, the following scripts are useful for the content types enumeration,
$sitecollection = Get-SPSite http://localhost
$sitecollection.RootWeb.ContentTypes include all the site content types
To get the specific content type by its ID
$c = $sitecollection.RootWeb.ContentTypes | where {$_.Id -eq "0x....."}
Also if create the custom content type page in visual studio, the elements.xml need to specify the PublishingAssociatedContentType such as,
<Property Name="PublishingAssociatedContentType" Value=";#Custom Article;#0x010100C568DB52D9D0A14D9.....;#" />
To list all the features
$site.Features to list all the site collection features.
$site.Features["GUID"] to get the specific feature
Also Get-SPFeature
Get-SPFeature -site http://site | where {$_.DisplayName -eq "..." }
There is a very useful tip to list the object properties
ps_object | Get-Member
Thursday, May 23, 2013
Add user as term store administrators from powershell
To be able to import the data into the term store, the user has to have the permission to do it, which is set in the "Managed metadata web service" service application.
Also it can be easily done in power shell as such,
$taxonomySession = Get-SPTaxonomySession -Site "http://localhost"
$termStore = $taxonomySession.TermStores["Managed Metadata Web Service Proxy"]
$termStore.AddTermStoreAdministrator("administrator")
$termStore.CommitAll()
Also it can be easily done in power shell as such,
$taxonomySession = Get-SPTaxonomySession -Site "http://localhost"
$termStore = $taxonomySession.TermStores["Managed Metadata Web Service Proxy"]
$termStore.AddTermStoreAdministrator("administrator")
$termStore.CommitAll()
Wednesday, May 22, 2013
Powershell script to read CSV file and XML
Working in SharePoint means a lot opportunity to use powershell. There is a specific powershell function very useful.
Import-csv $csvFilePath
This function reads the csv file and the first line will be the header line to create properties for each row.
For eg, if there is a csv file as
Name, Site, Url
aa,site a, http://sitea
bb,site b, http://siteb
After call Import-csv will load the data as a collection,
$data = Import-csv $csvfile
You can enumerate each row or filter them.
$data | foreach { $_. Name }
$data | where {$_.Name -eq "aa"}
And another convenient way to read data as xml format is just,
[xml] $xmldoc = Get-Content "xmldata.xml'
Sometimes if there is an error message such as "Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument", it is usually because of the mal-formatted XML.
Import-csv $csvFilePath
This function reads the csv file and the first line will be the header line to create properties for each row.
For eg, if there is a csv file as
Name, Site, Url
aa,site a, http://sitea
bb,site b, http://siteb
After call Import-csv will load the data as a collection,
$data = Import-csv $csvfile
You can enumerate each row or filter them.
$data | foreach { $_. Name }
$data | where {$_.Name -eq "aa"}
And another convenient way to read data as xml format is just,
[xml] $xmldoc = Get-Content "xmldata.xml'
Sometimes if there is an error message such as "Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument", it is usually because of the mal-formatted XML.
Everyday common SharePoint development issue and timps
Now I am back to start some SharePoint 2013 development work. Then there are some issues and useful links that I need every day. I write them down here in case later I need it again.
1. Deployment solution from visual studio and have this error,
"recycle iis application pool' :object reference not set to an instance of an object".
Just close visual studio and start again, then it worked.
2. Search in ShaePoint 2013 is a great function and their search API in REST is very useful,
http://blogs.msdn.com/b/nadeemis/archive/2012/08/24/sharepoint-2013-search-rest-api.aspx
The search address is in http://server/_api/search/query/?querytext='...'&selectproperties=''&startrow=..&rowlimit=..
3. Remove a web part from a page,
Sometimes the web part is not functionall as expected and needs to be disconnected from the page then enter the http://server/page_address?contents=1
4. Force reinstall fetaure in visual studio
Sometimes I am getting this error in deployment,
"Error occurred in deployment step 'Add Solution': A feature with ID xxxx-xxx-xxx-xxx has already been installed in this farm"
Need to set the AlwaysForceInstall = "True".
By the way, ImageUrl can be added to show a different feature image.
5. How to find the list template ID
Go to Site Contents -> Create list -> then right click on the page to get the url, the template ID is there.
Also a similar way can be used to get the associated content type ID.
1. Deployment solution from visual studio and have this error,
"recycle iis application pool' :object reference not set to an instance of an object".
Just close visual studio and start again, then it worked.
2. Search in ShaePoint 2013 is a great function and their search API in REST is very useful,
http://blogs.msdn.com/b/nadeemis/archive/2012/08/24/sharepoint-2013-search-rest-api.aspx
The search address is in http://server/_api/search/query/?querytext='...'&selectproperties=''&startrow=..&rowlimit=..
3. Remove a web part from a page,
Sometimes the web part is not functionall as expected and needs to be disconnected from the page then enter the http://server/page_address?contents=1
4. Force reinstall fetaure in visual studio
Sometimes I am getting this error in deployment,
"Error occurred in deployment step 'Add Solution': A feature with ID xxxx-xxx-xxx-xxx has already been installed in this farm"
Need to set the AlwaysForceInstall = "True".
By the way, ImageUrl can be added to show a different feature image.
5. How to find the list template ID
Go to Site Contents -> Create list -> then right click on the page to get the url, the template ID is there.
Also a similar way can be used to get the associated content type ID.
Wednesday, May 15, 2013
Add a sign in as different user in SharePoint 2013
By default, the "Sign-in as different user" option is removed in the site. And this is a very useful function for development and testing purpose.
In the folder,
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES
Edit the Welcome.ascx page to add the following link,
<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"
Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
MenuGroupId="100"
Sequence="100"
UseShortId="true"
/>
Done :)
In the folder,
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES
Edit the Welcome.ascx page to add the following link,
<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"
Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
MenuGroupId="100"
Sequence="100"
UseShortId="true"
/>
Done :)
Subscribe to:
Posts (Atom)