Archive for SharePoint

SharePoint 2013: Create Master Page using Visual Studio 2012

Scenario:

You can find many blogs on how to create SharePoint 2013 master page in Visual Studio 201. We faced following issue while creating master page. Long story, we need to create master pages for our new SharePoint 2013 environment. As with our previous experience, we decided to create them in Visual Studio. Everything works fine but when we try to deploy wsp via Visual Studio 2012, master pages are not uploaded in “Master pages and Layout Library”. The problem was in the XML that was written in “Elements.xml” file.

Resolution:

Before moving to XML that worked, we would like to share all the XML that didn’t worked. We are not sure why they didn’t work. Perhaps, anything wrong on our side.

XML that didn’t work:

<Elements
xmlns=http://schemas.microsoft.com/sharepoint/>

<Module Name=MasterPages” RootWebOnly=TRUE >

<File Path=MasterPages\ABCIntranet.master” 

Url=_catalogs/masterpage/ABCIntranet.master” 

IgnoreIfAlreadyExists=true >

<Property Name=UIVersion” Value=15></Property>

</File>

</Module>

</Elements>


<Elements xmlns=http://schemas.microsoft.com/sharepoint/>

<Module Name=MaterPage” Url =_catalogs/masterpage” List=116>

<File Path=MaterPage\ABCIntranetMasterPage.master” 

Url=ABCIntranetMasterPage.master
Type=GhostableInLibrary” IgnoreIfAlreadyExists=FALSE />

</Module>

</Elements>


<Elements xmlns=http://schemas.microsoft.com/sharepoint/>

<Module Url=_catalogs/masterpage” Name=MasterPage>

<File Url=ABCIntranetMasterPage.master” Type=GhostableInLibrary
IgnoreIfAlreadyExists=TRUE” 

Path=MasterPage\ABCIntranetMasterPage.master/>

</Module>

</Elements>

XML that did work is:

<Elements xmlns=http://schemas.microsoft.com/sharepoint/>

<Module Name=MasterPage” List=116” Url=_catalogs/masterpage
Path=MasterPage” RootWebOnly=TRUE>

<File Url=ABCIntranet.master” Type=GhostableInLibrary >

<Property Name=UIVersion” Value=15 />

</File>

</Module>

</Elements>

Advertisements

Leave a Comment

SharePoint:InputFormTextBox: Validation Issue after postback

Scenario:

We have placed a “SharePoint:InputFormTextBox” text control on our webpart and wanted to make it a “Required Field”. We added an ASP “RequiredFieldValidator” which works fine when we click submit.

We have other controls on the form as well. If an event is occurred and any other controls postback, then, the validation on “SharePoint:InputFormTextBox” fails to work if we try to submit.

Resolution:

We look into the issue and tried to resolve by adding implementing different solutions but nothing was working. In the end, found a reply on MS SharePoint forum that was buried in other replies. Suggested setting the initial property of “RequiredFieldValidator”.

Turned out the when webpart postback, somehow, “<DIV></DIV>” is added in “SharePoint:InputFormTextBox”. You can check it by editing the control “SharePoint:InputFormTextBox” after postback from some other control.

We set

RequiredFieldValidator3.InitialValue = “<DIV></DIV>”

in every control server-side code that postback.

Source: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentlegacy/thread/e9fbbd43-bef9-48fc-9a9f-0011514798e7/ Look at the last reply by “cschoenfeldt“.

Leave a Comment

Microsoft Security Bulletin – Vulnerabilities in SharePoint Could Allow Elevation of Privilege

Leave a Comment

SharePoint: Reduce space b/w webparts

Scenario:

We need to reduce space b/w webparts

Resolution:

SharePoint add a div after webaprt with class “ms-PartSpacingVertical” which has margin-top property set to 12px. Add class with the same name and make margin-top zero. In our scenario, webparts were added inside div with id “middle”, so we added following class

#middle .ms-PartSpacingVertical{

    margin-top: 0px !important;

}

Leave a Comment

SharePoint: Get List of Folders and Subfolders

Scenario:

A question on MSN requested for code to populate two drop downs from a document library. “DropDown A” should contain list of all the folders at the root. If we select any folder from “DropDown A”, “DropDown B” should be populated with list of all folders in the selected folder.

Resolution:

To get the list of all the folders at root, following code will help:

using(SPSite oSite = new SPSite(“Site_URL”))

{

SPWeb oWeb = oSite.OpenWeb();

SPList oList = oWeb.Lists[“DocumentLibraryName”];

SPFolderCollection oFolders = oList.RootFolder.SubFolders;

foreach (SPFolder oFolder in oFolders)

{

if (!oFolder.Name.Equals(“Forms”))

{

//use oFolder.Name property to populate DropDown A

}

}

}

Once selected, following code will populate “DropDown B” with list of subfolders:

SPFolder selFolder = oList.RootFolder.SubFolders[oList.Title + “/” + “Selected Folder Name”];

SPFolderCollection selSubFolders = selFolder.SubFolders;

foreach (SPFolder selSubFolder in selSubFolders)

{

//use subFolder.Name property to populate DropDown B

}

Comments (7)

SharePoint: Associate Workflow with a list programmatically

Scenario:

We need to associate a workflow with a list or create an instance of workflow for a list using SharePoint Object Model (OM)

Resolution:

In order to associate workflow with a list, we will be using CreateListAssociation method of SPWorkflowAssociaition class. We need following four values:

  • baseTemplate – The workflow template on which to base this workflow association.
  • Name – The name to give this workflow association.
  • taskList – The task list on which to create workflow tasks for this workflow association.
  • historyList – The list to which to log workflow history events

Code is as under:

using(SPSite spSite = new SPSite(“SiteURL”))

{

SPWeb spWeb = spSite.OpenWeb();

SPList assocList = spWeb.Lists[“NameOfTheList”];

SPWorkflowTemplate wflTemplate = spWeb.WorkflowTemplates.GetTemplateByName(“NameOfWorkflowTemplate”, System.Globalization.CultureInfo.CurrentCulture);

SPList wflTaskList = spWeb.Lists[“Tasks”];

SPList wflHistoryList = spWeb.Lists[“Workflow History”];

SPWorkflowAssociation wflAss = SPWorkflowAssociation.CreateListAssociation(wflTemplate, “NameOfTheWorkflow”, wflTaskList, wflHistoryList);

wflAss.AutoStartChange = false;

wflAss.AutoStartCreate = false;

wflAss.AllowManual = true;

spWeb.AllowUnsafeUpdates = true;

assocList.AddWorkflowAssociation(wflAss);

assocList.Update();

spWeb.AllowUnsafeUpdates = false;

}

Comments (1)

SharePoint: Workflow Migration

This is the second post related to SharePoint workflows. In first post, we have looked at the implementation details of the OOTB and SPD workflows. In the this post, we will look at the migration of OOTB and SPD 2010 workflows from one list to other or from one form to other.

Migration of Workflows: In order to migrate workflow from one site to other or from one server to other, we need to take care of three or four files mentioned previously. These files contain hard coded list and site GUID along with other details.

In case of OOTB workflow, instance details are stored in content database and can be seen in the table of “WorkflowAssociation”. Column “InstantiationParams” contains the details of users, order, due date etc. in XML format while other columns have of site / web / list IDs, name / description of workflow, task / history list IDs and names.

In case of SPD workflows, the definitions of workflow files are stored in list “workflows” created at the root of each site and web. In case of SPD 2007, files generated for a workflow are xoml, xoml.wfconfig.xml, aspx and xoml.rules if rules are used in the workflow.

Moving back to our original topic of migration, we need to change the GUID / ID of lists that are coded in xoml.wfconfig.xml file and you are done. A lot of third party workflow migrators are available but if you are interested in an open source solution, codeplex gives you hope.

http://spwflmigrator.codeplex.com/

This is a good resource for starting. Thanks rane_peinl J

In case of SPD 2010 workflows, files generated for a workflow are xoml, xoml.wfconfig.xml, xsn and xoml.rules if rules are used in the workflow. The big difference is the implementation of initiation form. In SPD 2007 workflow, initiation form is aspx page while in case of SPD 2010, initiation form is an InfoPath form. If you export the InfoPath form, add .cab with the form name and extract it, you will be able to find files that are generated as part of InfoPath form.

When we tried to migrate SPD 2010 workflow from one list to other, we were able to read xoml.wfconfig.xml and replace all the related IDs with the destination but we are unable to create a working InfoPath form. Although InfoPath is migrated successfully but when we try to start workflow, “Form has some error” message appeared. Creating a working initiation form for the migrated workflow doesn’t seem to be happening.

We do have third party solution that claims to migrate SPD 2010 workflow but I am waiting for their support response.

Comments (1)

Older Posts »