Archive for code

SharePoint: You cannot deploy this solution on this type of server computer as it is configured. This solution must be installed on a server of type: front-end Web server

Scenario:

We tried to deploy wsp via Visual Studio 2013 on our development server, deployment stopped with following error:

You cannot deploy this solution on this type of server computer as it is configured. This solution must be installed on a server of type: front-end Web server

We tried using PowerShell, but it hangs at “Deploying”. Tried solution like adding “loopback check” but it didn’t work in case of wsp deployment.

Resolution:

Finally, disconnecting and connecting configuration database did the trick but at the cost of creating new CA.

Steps are:

  1. Run cmdlet to disconnect configuration database
  • Disconnect-SPConfigurationDatabase –Confirm:$false
  1. Close PowerShell window and open new PowerShell window
  2. Run cmdlet to connect configuration
  • $passphrase = ConvertTo-SecureString -String “sharepoint@2013” -asPlainText -Force
  • Connect-SPConfigurationDatabase -DatabaseServer SQLServerInstanceName -DatabaseName SharePoint_Config -Passphrase $passphrase
  • Start-Service SPTimerv4
  1. Run SharePoint Configuration wizard and created new central administration.

We were able to deploy solutions via Visual Studio but newly created Central Administration need to deploy every wsp.


Advertisements

Leave a Comment

SharePoint: Create Dynamic SPQuery

Scenario:

We need to develop a webpart that searches a list in SharePoint. The search criteria are based upon user input. A simplified image of search criteria is as under:


Resolution:

After googling, we found a great solution:
http://sharepointcamlhelper.codeplex.com/

Suppose we have two checkboxes and two radio button, then our query should be like this:

SPQuery oQuery = new SPQuery();
CAMLManager mgr = new CAMLManager();
mgr.QueryGroups.Add(new QueryGroup("ColumnName", Types.FieldTypes.Text, Types.QueryTypes.Eq, "ColumnValue"));
mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.And, "ColumnName", Types.FieldTypes.Text, Types.QueryTypes.Eq, "ColumnValue"));
if (chkSelectGroup.Checked == true)
{
mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.And, "ColumnName", Types.FieldTypes.Text, Types.QueryTypes.Eq, ddlSelectGroup.SelectedItem.Text));
}
if (chkSubject.Checked == true)
{
mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.And, "ColumnName", Types.FieldTypes.Text, Types.QueryTypes.Contains, txtSubject.Text));
}
if (rbAnnByEmail.SelectedIndex != -1)
{
if (rbAnnByEmail.SelectedItem.Text == "Yes")
{
mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.And, "ColumnName", Types.FieldTypes.Text, Types.QueryTypes.Eq, "ColumnValue"));
}
if (rbAnnByEmail.SelectedItem.Text == "No")
{
mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.And, "ColumnName", Types.FieldTypes.Text, Types.QueryTypes.Eq, "ColumnValue"));
}
}
mgr.OrderBy.Add(new OrderBy("ColumnName", false));
string camlQuery = mgr.GetFullCAML();
oQuery.Query = camlQuery;

Issue:
One thing that doesn’t seems to be working is “ViewFields”. We have added following lines to restrict our query to specific fields, but it doesn’t seems to be working.

cmgr.ViewFields.Add(new ViewField("ColumnName"));
cmgr.ViewFields.Add(new ViewField("ColumnName"));
cmgr.ViewFields.Add(new ViewField("ColumnName"));
cmgr.ViewFields.Add(new ViewField("ColumnName"));
cmgr.ViewFields.Add(new ViewField("ColumnName"));


Update:
If we add following code, ViewFields seems to work

spQuery.ViewFieldsOnly = true;
spQuery.ViewFields = cmgr.GetViewFields().Replace("", "").Replace("", "");

Comments (1)

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 2101: Migrate List Views to SharePoint Online

Scenario:

We need to migrate List Views from SharePoint 2010 Server to SharePoint Online. We can use Web Services or Client Model. We decided to use Views Web Service.

Resolution:

First, we created a class which stores view information.

public class ListViewInfo

{

public ListViewInfo()

{

}

[DataMember]

public string listName { get; set; }

[DataMember]

public string viewName { get; set; }

[DataMember]

public string viewGUID { get; set; }

[DataMember]

public string openApplicationExtension { get; set; }

[DataMember]

public XmlNode viewFields { get; set; }

[DataMember]

public XmlNode viewQuery { get; set; }

[DataMember]

public XmlNode rowLimit { get; set; }

[DataMember]

public string type { get; set; }

[DataMember]

public bool makeViewDefault { get; set; }

[DataMember]

public XmlNode viewHeader { get; set; }

[DataMember]

public XmlNode viewBody { get; set; }

[DataMember]

public XmlNode viewFooter { get; set; }

[DataMember]

public XmlNode viewEmpty { get; set; }

[DataMember]

public XmlNode rowLimitExceeded { get; set; }

[DataMember]

public XmlNode viewToolBar { get; set; }

[DataMember]

public XmlNode viewAggregations { get; set; }

[DataMember]

public XmlNode viewFormat { get; set; }

}

We created two methods to get views information and to create views.

public static List<ListViewInfo> GetViewDetails(string listUrl)

{

List<ListViewInfo> listViewList = new List<ListViewInfo>();

ListViewInfo listView = new ListViewInfo();

string viewXML = string.Empty;

XmlDocument doc = new XmlDocument();

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

{

using (SPWeb spWeb = spSite.OpenWeb())

{

SPList spList = spWeb.GetList(listUrl);

SPViewCollection spViewColl = spList.Views;

foreach (SPView spView in spViewColl)

{

viewXML = spView.HtmlSchemaXml;

doc.LoadXml(viewXML);

XmlNode root = doc.FirstChild;

listView.listName = spList.Title;

listView.viewName = root.Attributes[“DisplayName”].Value;

listView.viewGUID = root.Attributes[“Name”].Value;

listView.viewFields = root.SelectSingleNode(“/View/ViewFields”);

listView.viewQuery = root.SelectSingleNode(“/View/Query”);

listView.rowLimit = root.SelectSingleNode(“/View/RowLimit”);

listView.type = spView.Type;

listView.makeViewDefault = spView.DefaultView;

listView.viewHeader = root.SelectSingleNode(“/View/ViewHeader”);

listView.viewFooter = root.SelectSingleNode(“/View/ViewFooter”);

listView.viewBody = root.SelectSingleNode(“/View/ViewBody”);

listView.viewEmpty = root.SelectSingleNode(“/View/ViewEmpty”);

listView.viewToolBar = root.SelectSingleNode(“/View/ViewToolbar”);

listView.viewAggregations = root.SelectSingleNode(“/View/Aggregations”);

listView.viewFormat = root.SelectSingleNode(“/View/Formats”);

listView.openApplicationExtension = spView.OpenApplicationExtension;

listViewList.Add(listView);

listView = new ListViewInfo();

doc.RemoveAll();

}

}

}

return listViewList;

}

public static void createOrUpdateListView(List<ListViewInfo> listViewList)

{

ViewSvr.Views viewSrv = new ViewSvr.Views();

viewSrv.Credentials = System.Net.CredentialCache.DefaultCredentials;

viewSrv.Url = “http://SiteURL/_vti_bin/Views.asmx&#8221;;

if (listViewList.Count > 0)

{

string listName = listViewList[0].listName;

XmlNode viewColl = viewSrv.GetViewCollection(listName);

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.LoadXml(“<root>” + viewColl.InnerXml + “</root>”);

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

nsmgr.AddNamespace(“XYZ”, “http://schemas.microsoft.com/sharepoint/soap/&#8221;);

foreach (XPSListView listView in listViewList)

{

XmlNode foundView = xmlDoc.SelectSingleNode(@”/root/XYZ:View[@DisplayName='” + listView.viewName + “‘]”, nsmgr);

if (foundView == null)

{

//add view

XmlNode nv = viewSrv.AddView(listView.listName, listView.viewName, listView.viewFields, listView.viewQuery, listView.rowLimit, listView.type, listView.makeViewDefault);

}

else

{

//update view

XmlNode uv = viewSrv.UpdateViewHtml2(listView.listName, foundView.Attributes[“Name”].Value, null, listView.viewToolBar, listView.viewHeader, listView.viewBody, listView.viewFooter, listView.viewEmpty, listView.rowLimitExceeded, listView.viewQuery,listView.viewFields, listView.viewAggregations,listView.viewFormat,listView.rowLimit, listView.openApplicationExtension);                    }

foundView = null;

}

}

}

P.S. We have used UpdateViewHtml2 Method to update the view but not able to find viewProperties. Please let me know if anyone find the mapping.

Also, please add web reference of Views Web Service in your project and replace following line with your web reference

ViewSvr.Views viewSrv = new ViewSvr.Views();

Leave a Comment

SharePoint 2010: Add ASP.NET AJAX Control Toolkit

Scenario:

We need to include “ASP.NET AJAX Control Toolkit” in our webpart.

Resolution:

1 – Download “ASP.NET AJAX Control Toolkit” binary version from following:

http://ajaxcontroltoolkit.codeplex.com/releases/view/33804

2 – Add assembly “AjaxControlToolkit.dll” into GAC using gacutil.exe

gacutil.exe /i “AjaxControlToolkit.dll”

3 – Add following line in “<assemblies>” section of the “web.config” file of specific web application

<add assembly=”AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e” />

4 – Add reference of “AjaxControlToolkit.dll” in your project for server side and for client side add following line:

<%@ Register Assembly=”AjaxControlToolkit” Namespace=”AjaxControlToolkit” TagPrefix=”ajax” %>

Leave a Comment

Older Posts »