Wednesday, March 13, 2013

Deploy Administrator Approved Forms - InfoPath 2010

Administrator-approved form templates

Administrator-approved form templates are available to any site collection on the SharePoint site and can contain code that requires full trust. They are individually verified, uploaded, and activated by a SharePoint site administrator. Administrator-approved form templates are maintained in a special document library that can be accessed only by administrators.

Deploy administrator-approved form templates

To deploy an administrator-approved form template, you must complete three actions after the form template has been designed: verify, upload, and activate. These steps can either be performed through the command-line interface or through the Central Administration site. You can upload a form template by using the Publishing Wizard in the InfoPath program, using the command line on a server running InfoPath Forms Services in the farm to which the form template will be deployed, or by using the Central Administration interface.
To deploy the form using central admin you can refer
http://technet.microsoft.com/en-us/library/cc262921.aspx
Using central admin method we can deploy one form at a time but if we need to deply many forms this process takes lot of time and effort. So I tried to automate this process using powershell. I have wrote a small powershell script to deploy these forms.
# Set the required variables
$siteURL = "
http://MySiteURL"
$publishingDirectory = "Source file location"
$settingsFile = "$publishingDirectory\InfoPathFormsList.txt"
$category = "My Category"
function Show-Progress([string]$activity, [string]$status, [int]$count)
{
if ($count % 4 -eq 1) {write-progress -activity $activity -status $status " _" ;}
if ($count % 4 -eq 2) {write-progress -activity $activity -status $status " \" }
if ($count % 4 -eq 3) {write-progress -activity $activity -status $status " |" }
if ($count % 4 -eq 0) {write-progress -activity $activity -status $status " /" }
}
foreach ($i in Get-Content -Path $settingsFile)
{
$formLocation = "$publishingDirectory\$i.xsn"
# Deactivate the InfoPath form
Write-Output "Deactivate " $i
Disable-SPInfoPathFormTemplate -Identity $i -Site $siteURL -ErrorAction:SilentlyContinue
# uninstall the InfoPath form
Write-Output "Uninstalling " $i
$formTemplate = Get-SPInfoPathFormTemplate -Identity $i -ErrorAction:SilentlyContinue
if ($formTemplate -ne $null)
{
Uninstall-SPInfoPathFormTemplate -Identity $i -ErrorAction:SilentlyContinue
}
$percent = 1
while ($formTemplate -ne $null -and $formTemplate.FormTemplateStatus -eq "Removing")
{
if ($count -eq 100) {$count = 0;}
write-progress -activity "Uninstalling $i" -status "Removing" -percentcomplete (++$count);
$formTemplate = Get-SPInfoPathFormTemplate -Identity $i -ErrorAction:SilentlyContinue;
}
write-progress -activity "Uninstalling $i" -status "Removing" -percentcomplete 100;
# Verify the InfoPath form
#Write-Output "Verifying " $i
#Test-SPInfoPathFormTemplate -Path $formLocation
# Upload the InfoPath form
Write-Output "Uploading " $i
Install-SPInfoPathFormTemplate -Path $formLocation -Confirm:$false
# Activate the InfoPath form
Write-Output "Activating " $i
Enable-SPInfoPathFormTemplate -Identity $i -Site $siteURL
# Modify the category of the form
Set-SPInfoPathFormTemplate -Identity $i -Category $category
}

To use this script

1. Copy this script in a notepad.
2. Change $siteURL =
http://MySiteURL
3. Create a folder sourcesFiles and paste your InfoPath form template (.xsn) files in it.
4. Enter your source folder path in $publishingDirectory = "Source folder path"
5. Save this notepad text as PowerShell script (myScript.ps1).
6. Create a InfoPathFormsList.txt file in the same folder and write all InfoPath form template names (i.e. myTemplate.xsn) in it.
7. Open SharePoint 2010 management shell and run this PowerShell script

Monday, October 8, 2012

Useful links for Access Services 2013 in SharePoint 2013




Intro to Access 2013


SQL and Access 2013


Access Blog


Three part series. This is part 1.  Gives a good insight to internals of SharePoint.


Improving the Reach and Manageability of Microsoft Access 2010 Database Applications with Microsoft Access Services


Access 2013 desktop database reference





Access 2013 web app demo


Wednesday, August 29, 2012

Lookup field dropdown position issue

I was trying to create a custom webpart that will display a form to submit data in a list. The list had few lookup fields.
Whenever, I click on that image it displays us with a drop-down containing all the values, but the funniest part is you can select a particular item either by double click or by selecting it once and clicking it else where on the page or by tabbing system of the keyboard. But I want it work like a normal drop-down selection in other words just with a single click and also the control should be closer to other controls from usability perspective.


To fix this issue. you need to set InDesign ="true";

 Ex.BaseFieldControl webControl = field.FieldRenderingControl;

webControl.ID =
string.Format("ctrl_{0}_{1}", field.InternalName, pplCount);


webControl.FieldName = field.Title;

webControl.ItemContext =
SPContext.GetContext(HttpContext.Current, lstReqData.DefaultView.ID, lstReqData.ID, lstReqData.ParentWeb);

webControl.RenderContext = SPContext.GetContext(HttpContext.Current, lstReqData.DefaultView.ID, lstReqData.ID, lstReqData.ParentWeb);

webControl.ControlMode = SPControlMode.New;

webControl.ListId = lstReqData.ID;

webControl.InDesign =
true;

 If you are using form field you can set it by following changes in aspx page

<SharePoint:FormField runat="server" InDesign="true" ID="myFieldId" ControlMode="New" FieldName="myFieldName" />

Wednesday, June 6, 2012

Use Metadata Navigation in Wiki Pages (Sharepoint 2010)

If you want to use Metadata navigation tree in Wiki Page, you have to do the following:
  • Activate Metadata Navigation and Filtering feature on site level
image
  • Navigate to Library settings page of your “Pages” library and select Metadata navigation settings
  • From “Configure Navigation Hierarchies” select “Wiki Categories” and click “Add” and “OK”
image
  • Navigate to Pages library again
http://<Your Wiki Site Url>/Pages/Forms/AllItems.aspx

But when you click on any of the pages on the right panel, the navigation tree will disappear.

 

You have to change the master page or better to create and deploy a new one (via Sharepoint Designer or wsp)
You have to include a reference to MetadataNavTree control and put it in some placeholder (QuickLaunchNav) on the master page file.
  • Put this markup in the beginning of the page
<%@ Register TagPrefix="wssuc" TagName="MetadataNavTree" src="~/_controltemplates/MetadataNavTree.ascx" %>
  • Put this code in <asp:ContentPlaceHolder id="QuickLaunchNav" runat="server"> tag
<asp:ContentPlaceHolder id="QuickLaunchNav" runat="server">
<wssuc:MetadataNavTree id="mdnt" runat="server" />

The result is:

Monday, May 21, 2012

Calling Javascript / Jquery / ECMA script from an UpdatePanel in SharePoint

You've probably used ClientScript.RegisterStartupScript in your SharePoint application page and it works just fine.
for example:-
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "<script type=\"text/javascript\">SP.UI.ModalDialog.commonModalDialogClose(0);</script>");
 However, if you try it within an UpdatePanel control, you would notice that it simply doesn't execute.

The solution to this problem is to use ScriptManager.RegisterStartupScript instead. You can call it like so:
ScriptManager.RegisterClientScriptBlock(UpdatePanelSites, UpdatePanelSites.GetType(), "Close", "SP.UI.ModalDialog.commonModalDialogClose(0);", true);

Thursday, January 12, 2012

Select Distinct or Unique values from SharePoint List



I was looking around for the simple way of getting unique values from SharePoint list without affecting performance. I have seen several ways of doing it. For example, we can get all the items and then check if item exists in the array or some other collection. Another example, you can load your data into DataTable and then select unique values using DataTable method, following is snippet of code below on how to use it

GetUniqueColumnData("List Name", "ColumnName");


private void GetUniqueColumnData(string ListName, string ColumnName)
{
try
{
using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = site.OpenWeb())
{
DataTable dtList = new DataTable("TableName");
SPList list = web.Lists[ListName];
if (list != null)
{
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='" + ColumnName + "'/></Order By><FieldRef Name='" + ColumnName + "'/>";
dtList = list.GetItems(query).GetDataTable();
dtList = new DataView(dtList).ToTable(true, new string[] { ColumnName });
}
}
}
}
catch (System.Exception ex)
{
LoggingService.LogErrorInULS(ex.Message + "Stack Trace: "+ ex.StackTrace,TraceSeverity.High);
}
}

but I discovered one very simple method for selecting Distinct Values in SharePoint called GetDistinctFieldValues. Please see snippet of code below on how to use it


using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = site.OpenWeb())
{
SPList objList = web.Lists["List Name"];
SPField field = objList.Fields.GetField("Field Name");

Object[,] values;
uint numberValues = objList.GetDistinctFieldValues(field, out values);

for (int i = 0; i < numberValues; i++)
comboBox1.Items.Add(values.GetValue(0, i).ToString());

}
}