Hi,
If you are creating a sandbox solution let's say for SharePoint online and if you wish you create a visual web part, then you have no choice for that directly.
However you can still download an extension to your Visual Studio 2010 which will allow you to create a visual web part in sandbox environment.
It is called the VS 2010 SharePoint power tool.
http://visualstudiogallery.msdn.microsoft.com/8e602a8c-6714-4549-9e95-f3700344b0d9
I hope this helps.
SharePoint Kings
SharePoint Kings,Technosavvy guys hunting SharePoint Challenges... SharePoint 2013, SharePoint 2010, MOSS 2007, Windows Workflow Foundation, Project Server and Other Related Technologies.
Sunday, May 19, 2013
Thursday, April 25, 2013
Save list as a template and create list from template using PowerShell
In this post we are going to see how we can save list as a template that saves it to the list template gallery and then how we can create a new list / library from the template from the saved template earlier.
Here is a simple script that we can write in PowerShell to do that
Here we are saving shared documents library as a template and then creating a library from the saved template.
[xml]$xmlfile = Get-Content ConfigFile.xml
foreach( $sitecoll in $xmlfile.Configuration.SiteCollection)
{
$site = $sitecoll.name
}
$spSite= Get-SPSite $site
$web = $spSite.OpenWeb()
Write-Host -foregroundcolor yellow 'Saving list as a template.....'
$list = $web.GetList("/sites/SharePointSite/Shared Documents/")
$list.SaveAsTemplate("SDWITHDOCSET","SD with DOCSET","Shared Doc with Doc Set",1)
Write-Host -foregroundcolor Green 'Saving list as a template successfully'
Write-Host -foregroundcolor yellow 'Creating documents library from the template...'
$listTemplates = $spSite.GetCustomListTemplates($web)
$web.Lists.Add("SDFromTemplateUsingPS", "", $listTemplates["SD with DOCSET"])
Write-Host -foregroundcolor green 'Creating documents library from the template completed successfully.'
I hope this helps.
Here is a simple script that we can write in PowerShell to do that
Here we are saving shared documents library as a template and then creating a library from the saved template.
[xml]$xmlfile = Get-Content ConfigFile.xml
foreach( $sitecoll in $xmlfile.Configuration.SiteCollection)
{
$site = $sitecoll.name
}
$spSite= Get-SPSite $site
$web = $spSite.OpenWeb()
Write-Host -foregroundcolor yellow 'Saving list as a template.....'
$list = $web.GetList("/sites/SharePointSite/Shared Documents/")
$list.SaveAsTemplate("SDWITHDOCSET","SD with DOCSET","Shared Doc with Doc Set",1)
Write-Host -foregroundcolor Green 'Saving list as a template successfully'
Write-Host -foregroundcolor yellow 'Creating documents library from the template...'
$listTemplates = $spSite.GetCustomListTemplates($web)
$web.Lists.Add("SDFromTemplateUsingPS", "", $listTemplates["SD with DOCSET"])
Write-Host -foregroundcolor green 'Creating documents library from the template completed successfully.'
I hope this helps.
Monday, April 22, 2013
Document Set Save as a template problem
In this post, we are going to see one problem which is not
been addressed properly. I think not even from Microsoft in the form of SP1 or
even in the form of CU.
Problem is, you have one document library and you have
document set in that library with many other documents inside each document
set.
The problem is when you save a library as a template with
content and when you create a document library based on the template, you can
see that the document sets have come. You can even see the icon indicating that
these are the document sets. However when you click on the document set, boom!!
page not found.
I did not find answer anywhere. Even if you save a web as a
template including content and then try to create a web based on the template,
you see a strange thing. In the document library, you will find those document
set icon as folders not as a icon of the document sets.
Well only thing that I observed is you go ahead and manually
edit the properties of those document sets and change the content type to the
document set, that will resolve the issue and when you click , you get the
welcome page and documents that were there inside the document set while saving
site or list as a template.
But this is not a solution. Imaging you have more than 100
libraries and each having more than 50 document sets with each almost 100
documents inside it. !!! Not sure what Microsoft is thinking on this.
If anyone has come across to this and have found proper
solution, please do let us know.
Friday, April 19, 2013
Create document set programmatically
In this post
we are going to see how to create a document set in SharePoint
programmatically.
To start
with we need to activate the feature called document set at the site collection
level.
If you would like to know more about document set, then I would
recommend you reading Understand Document Set to get a fair idea on what document set is
and what it offers.
I have one
document library with the name Shared Document. To add document set programmatically,
we first need to enable the content types on this library. So go to the library
settings, advance settings and enable the allow management of content types.
Now click on
add from existing content types.
On the page
look for document set content type and add it to the library.
So you
should have something like this
Now I am
showing this with an example of feature activated event. I have one feature and
on activating the feature I am creating a document set programmatically.
Here is a
code that you need to write.
Now if you
see what we have done here is first we have taken document set content type in
to a code from current web. This will not work if you have not activated
document set feature at a site collection level.
Document set
has properties, so we have set one property - document set description. This
needs to be done with HashTable.
Then we are
creating a document set by DocumentSet.Create method. To get this done you need
to add reference to one DLL and for the HashTable you need to one DLL.
These are
the DLLs you need to refer.
using
System.Collections;
using
Microsoft.Office.DocumentManagement.DocumentSets;
After
creating Document Set, the important line of code to note is the ProgId of the
item to be set to SharePoint.DocumentSet.
If you do
not do this, then all you get is just a folder and not actual document set. You
can see the difference in the icon as well as when you click on the folder.
Finally we
update the item.
So let's
deploy the WSP and activate the feature and see what happens.
See the
icon. Icon indicates that this is the document set and not the plain folder. Click
on the title.
See the
description is also set. You can also set additional properties at the time of
creating document set.
I hope this
helps.
Thursday, April 11, 2013
Checking for validation error programatically in InfoPath
In case if you are writing a code in button click event of InfoPath page and you would like to validate the required fields input or any other validation, then here is a one liner code that you need to write.
this.errors.count
if the count is 0 that means there is no error, else there are errors.
Happy coding!!
this.errors.count
if the count is 0 that means there is no error, else there are errors.
Happy coding!!
Thursday, April 4, 2013
Allocate tasks to users inside group in start approval process in SharePoint Designer
In this post we are going to see how we can assign tasks to
the users inside start approval process on this item with these users action
inside SharePoint designer.
To demonstrate I have one list with one title column and one
group name column which has group as well as users settings done.
Let us open the SharePoint Designer and connect to the site.
Click on list workflow and select list on which you want to add the workflow.
Select start approval
process from the actions menu.
Click on these users.
Select workflow lookup and then from current item, select
the field.
Configure this workflow on start automatically on create and
on edit
Now go ahead and create one item in the list.
I have added one list item with selecting engineers as a
group on which approval will start.
As you can see workflow is in progress.
Click on in progress and as you can see it is assigned to
the group and not to the users inside group.
So how to actually allocate tasks to the users inside the
group. Well there is a small change.
Go back to the workflow in designer. Select the step and
click on advanced properties from ribbon.
And change the expand group to yes.
Publish the workflow now.
Create one more item in the list, click on the in progress
status of the workflow. and there you go.
Task is now allocated to the user inside the group. As this
approval is set as a serial, go ahead and approve this. You will see the next
task allocated to the next user in the group.
I hope this helps.
Tuesday, April 2, 2013
Display list item in edit mode in InfoPath Form Web Part
In this post we are going to see how we can open a list item
in edit mode in InfoPath Form Web Part. This initially seems to be an easy job.
But it is not.
I really had to invest a lot of time figuring out this
solution. What we want to achieve is actually a list form customized using
InfoPath by using customize this form in InfoPath ribbon option and then by
using the InfoPath form web part we display the form of the list.
I have a list called orders.
and I have used customized the form in InfoPath option from
ribbon so that new item, edit item and view item opens up in InfoPath form and
not the list form.
If you select the list item and click on edit the item, you
can see item is opened in the InfoPath.
Now here comes a tough part. Assume that you want to have
another web parts on the page and on the same web part page you would like to
have this order list item new entry form to be displayed.
Well, this is not as tough as you think. you can simple add
the InfoPath form web part and then set the list name to order and you are good
to go.
Once you click on ok, you can see the form has been added on
the web part.
Now comes the challenging part, how would you open any list
item in the InfoPath Form Web Part. Now again this seems an easy job but it is
not as I stated earlier.
I had to go through lot of blog posts and articles. Many of
them mentioned that you need to have source list and then bind the connection
between InfoPath Form web part and source list so that when you select the
source list item, that item gets populated in the InfoPath Form Web Part.
However this is not the solution that we want. We cannot add
a source list in our case, orders to the same page and connect these two web
part.
There can be a scenario where you are just passing ID of the
list item from another page and based on the query string you want to show the
edit form in the InfoPath form web part.
So here is a solution that I came out with. But yes if you
do not have code option available to you, then you have to go with the connect
web part approach. But for that you will have a list also displayed on the same
web part page.
All we need to do is create one simple web part (not the
visual web part) . add a reference to the c:\Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\14\ISAPI\Microsoft.Office.Server.dll DLL.
protected override void CreateChildControls()
{
BrowserFormWebPart web = new BrowserFormWebPart();
web.FormLocation = @"{siteURL}/Lists/Orders/Item/editifs.aspx?List={list
GUID}&LItemID={ITEMID}&Source={siteURL}%2FLists%2FOrders%2FAllItems%2Easpx&ContentTypeId=0x01005AFFDCC34451FF46B97FDD902EA436AF";
this.Controls.Add(web);
}
Just replace the List GUID, site URL and ID with the actual
list GUID, site URL and list item ID. you can get these through query string or
as per your requirement.
Deploy the web part and you are good to go. Now you have a
InfoPath Form web part which shows list item in edit mode.
Thursday, March 28, 2013
Add web part page using PowerShell
Imagine a scenario where you need to create 100 web part
pages with different templates. You would spend a lot of time creating those
pages. One of the approaches can be having a PowerShell script which can create
web part pages for templates that you want.
Here is a simple script that creates web part pages in a
loop.
[xml]$xmlfile = Get-Content ConfigFile.xml
foreach( $sitecoll in $xmlfile.Configuration.SiteCollection)
{ $site = $sitecoll.name }
$spSite= Get-SPSite $site
$web = $spSite.OpenWeb()
$layoutTemplate = 4 # Template code
$web = $spSite.OpenWeb()
$list = $web.GetList("/sites/SharePointSite/SitePages/")
$i = 1
while ($i -le 5)
{ Write-Host $pageTitle = "WebPartPage& + $i
$xml = "<?xml version=""1.0"" encoding=""UTF-8""?>
<Method ID=""0,NewWebPage""><SetList Scope=""Request"">" + $list.ID + "</SetList><SetVar Name=""Cmd"">NewWebPage</SetVar><SetVar Name=""ID"">New</SetVar><SetVar Name=""Type"">WebPartPage</SetVar><SetVar Name=""WebPartPageTemplate"">" + $layoutTemplate + "</SetVar><SetVar Name=""Overwrite"">true</SetVar><SetVar Name=""Title"">" + $pageTitle + "</SetVar></Method>"
$result = $web.ProcessBatchData($xml)
$i++
Write-Host -foregroundcolor Green $pageTitle 'created successfully'
}
and when you run here is the output of the script and then
final result
If you observe closely here we have specified layouttemplate,
we have specified 4. This related to various templates like three column, four
columns, headers the template that we select while creating web part page.
Possible
LayoutTemplate values are :
# 1 - Full Page, Vertical
# 2 - Header, Footer, 3 Columns
# 3 - Header, Left Column, Body
# 4 - Header, Right Column, Body
# 5 - Header, Footer, 2 Columns, 4 Rows
# 6 - Header, Footer, 4 Columns, Top Row
# 7 - Left Column, Header, Footer, Top Row, 3 Columns
# 8 - Right Column, Header, Footer, Top Row, 3 Columns
Thursday, March 21, 2013
Set custom task field value in Start Approval action in SharePoint Designer
In this post
we are going to see how you can set custom field that is in the task list from
the designer when you use Start Approval action.
First take
any list into consideration. Open SharePoint Designer 2010, connect to the
site. Click on list workflow, select that list and create a workflow, give a
name and description. and add start approval process action to designer.
Set it like
this.
Now click on
Approval. This will take you to the form where you can customize the entire
approval process.
We are
interested in change the behaviour of single task.
But before
moving into this, observe task form fields on right. We need to create one task
form field in this. Click on new. If you already have site column defined, you
can click on add from site columns.
as you can
see it is set to optional.
Now click on
change the behavior of single task.
Before you
can access task field. Go ahead and publish the workflow.
go to tasks
list and list settings. Observe that designer has created a field for you.
Coming back
to the designer add set task field to value action.
You will get
the WF name field here select WF Name
and set the
value to Order WF. Go to the workflow settings screen and select start workflow
on create and on edit.
Save and
publish the workflow. Go to the orders list and add an item. You can see
workflow has started.
Go to task
list.
Now if you click
on the task title, you can see the WF Name field is shown on the form
go back to
designer and go to the customizing approval process.
From the
task form fields, set from optional to hidden. Now save and publish the
workflow.
Again click
on task list item and see that field is not visible on the form now.
I hope this
helps.
Tuesday, March 19, 2013
Create Managed Metadata Site Column in SharePoint 2010
In this post
we are going to see how we can create a site column that links with the managed
meta data.
Creating a
site column that holds a value from managed meta data term store is not
directly available.
We first
need to create a site field which is of type taxonomy and then we need to
create one feature which is scoped at site level and in feature activation we
access the taxonomy store and set the site column to required term set.
Go to site settings,
under site administration click on term store management. I have following
settings.
Now let's
create one Visual studio project. Select blank project.
Now add
SharePoint content type project item.
Choose item
content type. This is a sample that I have.
Finally I
have something like this.
Now add an
event receiver to the site level feature.
What we are
doing here is we are first taking reference of the field that we created. Then
we take a term store in to the account and then locate the Microsoft group.
After that we take Web Technologies group and then associate this group to our
site column.
public
override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site =
properties.Feature.Parent as SPSite;
Guid fieldId = new
Guid("{B87F6D98-564F-43CA-B4A6-1539A3A3E7C2}");
if
(site.RootWeb.Fields.Contains(fieldId))
{
TaxonomySession session = new
TaxonomySession(site);
if (session.TermStores.Count !=
0)
{
var termStore =
session.TermStores["Managed Metadata Service"];
foreach (Group grp in
termStore.Groups)
{
if (grp.Name ==
"Microsoft")
{
var group = grp;
var termSet =
group.TermSets["Web Technologies"];
TaxonomyField field
= site.RootWeb.Fields[fieldId] as TaxonomyField;
field.SspId =
termSet.TermStore.Id;
field.TermSetId =
termSet.Id;
field.TargetTemplate = string.Empty;
field.AnchorId = Guid.Empty;
field.Update();
break;
}
}
}
}
}
Deploy the
project.
To check this,
go to a task list. go to the list settings and enable the management of content
type.
Once enabled, add from existing site content type and add the SPKings
content type.
and there
you go
I hope this
helps.
Subscribe to:
Posts (Atom)
Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!
If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com