Archive for Visual Studio 2010

SharePoint 2010: Debugging Visual Studio 2010

Method I:

  1. Go to “Debug” and select “Attach to Process”
  2. Make sure “Show processes in all sessions” checkbox is checked
  3. Select all “w3wp.exe” processes and click on “Attach” button

If it does not work,

  1. Go to “Debug” and select “Attach to Process”
  2. Click on “Select…”.”Select Code Type” window will appear
  3. Select “Debug these codes types” and check “Managed (v2.0, v1.1, v1.0)” only

Method II:

  1. Write “System.Diagnostics.Debugger.Launch()” in the code where you want to attach debugger
  2. When you run the code, a popup window will appear asking for attaching debugger.
  3. Click “Yes” and guide to appropriate instance of Visual Studio

Method III:

Use third party software like:

  1. Visual Studio 2010 extension for helping SharePoint 2010 debugging
Advertisements

Leave a Comment

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 Ribbon: Hide Button from Discussion Forum New Item Window

Scenario:

We need to hide “Save / Cancel / Paste / Cut / Copy / Attach File” buttons from discussion forum “New Item” window:

Resolution:

Following XML worked:

<CustomAction


Id=RemoveRibbonButton


Location=CommandUI.Ribbon
RegistrationId=108


RegistrationType=List>

<CommandUIExtension>

<CommandUIDefinitions>

<CommandUIDefinition
Location=Ribbon.ListForm.Edit.Commit/>

<CommandUIDefinition
Location=Ribbon.ListForm.Edit.Clipboard/>

<CommandUIDefinition
Location=Ribbon.ListForm.Edit.Actions/>

</CommandUIDefinitions>

</CommandUIExtension>

</CustomAction>

</Elements>

 

Before:

After:

Comments (4)

SharePoint Object Model: SPField – Internal Name vs Display Name

Scenario:

Some days back “We need to populate an asp DropDownList control with all possible values of a choice column created in a specific SharePoint list“. All done but when we tried to populate dropdowns using oList.Fields, following exception generated:

Field with name “XYZ” was not found.

Resolution:

We were using the following code:

SPField oField = oList.Fields[“XYZ”];

We were using internal name to get the reference of SPField and it was generating exception. The reason is that oList.Fields[] take following three values:

oList.Field[Guid id] Gets the field using unique identifier
oList.Field[int iIndex] Gets the field object at the specified index in the collection
oList.Field[string displayName] Gets the field with the specified display name for the collection

The trick is in the last one. We are used of getting list item value using internal name but here we are required to use display name. So, we switched our implementation to GUIDs as fortunately we are also creating list and fields using feature in the same project.

This also clears another concern that why we are required to use internal names instead of display name when accessing a list item specific field value using internal name like listItem[“Field Internal Name”]. It may be due to the fact that user can any time change the display name of the field and our code will crash. As in the above example we preferred to switch to GUIDs instead to display name. Other than this, it may also be due to that fact that there are some characters which needs to be changed when translating display name to a URL.

Leave a Comment

SharePoint 2010: Display titles instead of URL’s in WhatsPopularWebPart

Scenario:

We need to display / render titles instead of the URL’s in “WhatsPopularWebPart”.

Resolution:

Google the problem and found following blog with an excellent idea how to accomplish above:

http://rolandoldengarm.wordpress.com/2011/04/08/whatspopularwebpart-render-titles-instead-of-urls/

As per “Roland Oldengarm” already stated that we “to created a webpart derived from WhatsPopularWebPart and implemented also ICallbackEventHandler”. Started working on it and found some implementation issues. First, we need to change the Regex and second, we need to change the code.


public class TestWebPart :

Microsoft.Office.Server.WebAnalytics.Reporting.WhatsPopularWebPart, ICallbackEventHandler

{

private const string ItemRegEx = @”<span dir=’ltr’>(?<url>[^<]*)</span>”;

private static string ReplaceUrlsWithTitles(string html)

{

if (Regex.IsMatch(html, ItemRegEx))

{

html = Regex.Replace(html, ItemRegEx, delegate(Match match)

{

var url = match.Groups[“url”].Value;

string title = url;

using (SPSite spSite = new SPSite(SPContext.Current.Site.Url))

{

using (SPWeb spWeb = spSite.OpenWeb(title))

{

try

{

var item = spWeb.GetListItem(title);

if (item != null)

{

title = item.Title;

}

}

catch (Exception e) { }

}

}

return
“<span>” + title + “</span>”;

},RegexOptions.IgnoreCase);

}

return html;

}

string ICallbackEventHandler.GetCallbackResult()

{

return ReplaceUrlsWithTitles(base.GetCallbackResult());

}

void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)

{

base.RaiseCallbackEvent(eventArgument);

}

}

Comments (33)

SharePoint 2010: Ribbon Customization – Adding button in Editing Tool Tab

Scenario:

When a user click in Content Editor web part, a button appear in the “Editing Tool -> Insert” tab.

Resolution:

Following XML did the trick and we deploy it as feature.

<CustomAction
Id=Ribbon.Add.Button

Location=CommandUI.Ribbon>

    <CommandUIExtension>

      <CommandUIDefinitions>

        <CommandUIDefinition
Location=Ribbon.WikiPageTab.PubPageActions.Controls._children>

          <Button

          Id=Ribbon.WikiPageTab.PubPageActions.AddLinkButton

          Sequence=22

          Image16by16=/_layouts/images/PPEOPLE.GIF

          Image32by32=/_layouts/images/PPEOPLE.GIF         

          Command=AddLinkButton

          LabelText=Add Link Button

          ToolTipTitle=Add Link Button

          ToolTipDescription=Create link.

          TemplateAlias=o2 />

        </CommandUIDefinition>

        <CommandUIDefinition

        Location=Ribbon.WikiPageTab.Scaling._children>

          <MaxSize

            Id=Ribbon.WikiPageTab.Scaling.PubPageActions.MaxSize

           Sequence=15

            GroupId=Ribbon.WikiPageTab.PubPageActions

            Size=LargeLarge />

        </CommandUIDefinition>

      </CommandUIDefinitions>

      <CommandUIHandlers>

        <CommandUIHandler
Command=AddLinkButton
CommandAction=javascript:AddLinkButton();
EnabledScript=javascript:returningtrue(); />

      </CommandUIHandlers>

    </CommandUIExtension>

  </CustomAction>

Leave a Comment

Older Posts »