Finally back to Blog after a long time, so starting with a short one!
Recently I had to deal with a requirement to provide Tree like navigation menu, as I am very much familiar with DynaTree using FancyTree (DynaTree is apparently being retired) was a no brainer however the tree navigation had to be accessible i.e. users should be able to navigate through the tree using TAB and Arrow key and pressing ENTER on the tree node behaves like a click event.
FancyTree renders ULs and Lis and you can navigate through the tree using Arrow keys but using TAB was a problem also pressing the ENTER key on the Tree node had no effect, so here is a little extension to FancyTree which provides that functionality.
Extension basically Adds tabindex=0 to Tree node and captures ENTER key event to perform action on the node, I only needed to either expand/collapse the node or navigate to the Href.
Ah also first time using Git -:)
On my current project we had a requirement to drop a file onto an SFTP server. SharpSSH seems to the only free and open source option around for .NET
Some of the pain points of SharpSSH
- SharpSSH was written in older version of .NET and relies on algorithms in Org.Mentalis.Security.Cryptography for encryption and hashing which is now natively supported by System.Security.Cryptograph so using SharpSSH as is does not seem right
- Sftp implementation does not support deleting a file (although it is very simple to add that!)
- Not complied with a Strong name key
Making above changes looked easy enough, so here is the download of SharpSSH – SFTP component for .NET which:
- Uses algorithms in System.Security.Cryptograph instead of Org.Mentalis.Security.Cryptography
- Compiled using .NET 3.5 with strong name and Project converted to Visual Studio 2008
- Supports Deleting a file, directory and renaming over SFTP
Some customary screen shots!
WSP Solution can be downloaded from here. Once the package is deployed, Activate the Kark SharePoint Web Parts feature at Site Collection level and Tab Accordion web part will be available in the Web Part Gallery.
Download WSP Here
Here is a screenshot
Please excuse the ugly looking Tabs, but hopefully CSS should be really easy to change
A Quick post! On a recent project we had a custom control that was showing document version history information such as “Created By” and “Date Created” in a table format, it was looking all good. After the day light savings time (British Summer Time) one of the tester spotted a bug in document version history control where “Date Created” was still showing the GMT time, it looked like SPListItemVersion.Created was not respecting day light savings time.
TimeZone.xml looked good and every other Dates on the site were showing correct time. It turns out that SPListItemVersion.Created was only showing time in GMT (Don’t know why!) so a simple fix was to convert the time into local time at the render time.
lblDateCreated.Text = version.Created.ToLocalTime().ToString();
Recently I have been working on a large Content Management solution that required 300+ custom Managed/Metadata Properties in MOSS Search and had requirements to allow user to search on all of the Metadata Properties. MOSS Search Index was also used to run a number of reports such as “What Asset (Image, Video, Document etc) is used on what page?”
While working with MOSS Search I came across a number of things that I think are worth sharing.
Programmatically setting up Shared Scope
APIs to work with MOSS Search related Administration tasks such as creating Scopes, Managed Properties etc are very straight forward and well documented under Getting Started with the Enterprise Search Administration Object Model
But if you want to set up a shared scope, then it’s not very obvious from API how to do it. ScopeCollection.Create method as shown below takes owningSiteUrl as a parameter and to set up a shared scope just pass in null for owningSiteUrl and the scope will be created as a Shared Scope!
public Scope Create (string name,string description, Uri owningSiteUrl, bool displayInAdminUI,string alternateResultsPage,ScopeCompilationType compilationType)
Programmatically setting up “Include values from a single crawled property based on order specified”
Programmatically setting up mappings to crawled properties is straight forward, if you want to add multiple crawled properties and include value only from a single crawled property based on the order than from the UI, you can simply check the radio button next “Include values from a single crawled property based on order specified”.
To do it programmatically add multiple Crawled properties to MappingCollection and then set ManagedProperty.RespectPriority property to true, here is some code (pseudo code really!) to add multiple crawled property mappings
Schema propertiesSchema = new Schema(SearchContext.Current); ManagedPropertyCollection managedProperties = propertiesSchema.AllManagedProperties; ManagedProperty managedProperty = managedProperties["Test Property"]; MappingCollection mappingCollection = managedProperty.GetMappings();//Create Crawled Property Mappings Mapping propMapping = new Mapping(new Guid("00130329-0000-0130-c000-000000131346"), "ows_Modified_x0020_By", "31",managedProperty.PID); Mapping propMapping1 = new Mapping(new Guid("b725f130-47ef-101a-a5f1-02608c9eebac"), "11","31",managedProperty.PID);//Add in the order in which you want it to appear in the Admin UI mappingCollection.Add(propMapping); mappingCollection.Add(propMapping1); managedProperty.SetMappings(mappingCollection); // You have to do this for Mappings to work //Tell it to respect priority! managedProperty.RespectPriority = true; managedProperty.Update();
It takes a Guid (crawledPropset) which is the category of crawled property (SharePoint, People, etc) and also takes an int (crawledPropertyVariantType) which represents the DataType of crawled property, I find it annoying that list of possible values crawledPropset and crawledPropertyVariantType is not very handy so here are the possible values
Some Possible Values of crawledPropertyVariantType
|Something to do with Custom field||4127|
*Please note that above values are what I have encountered till now *
Commonly Used crawledPropset
If you need to programmatically set properties on ContentByQueryWebPart to filter the data by approval status than FilterField is _ModerationStatus FilterType is ModState
webPart.FilterField1 = "_ModerationStatus"; webPart.FilterType1 = "ModStat"; webPart.FilterValue1 = "Approved";
I have been struggling to find information on how to add RSSAggregatorWebPart to a page. First I started with doing something like
RSSAggregatorWebPart rssViewer = new RSSAggregatorWebPart(); rssViewer.FeedUrl = "http://ketulpatel.wordpress.com/feed/"; rssViewer.ID = "rssFeed"; rssViewer.DataSourcesString = dataSourceString.ToString(); rssViewer.Title = "My Blog"; //AddWebPart is an helper method to add a webpart to a page AddWebPart(web,rssViewer,"default.aspx","CenterColTop",0);
That added the web-part to the page but when rendering the Page, web part gave an error asking to check error logs for errors and error log under 12 hive contained following error
RssWebPart: Exception handed to HandleRuntimeException.HandleException System.ArgumentNullException: Value cannot be null. Parameter name: key at Microsoft.SharePoint.WebControls.CacheObject.LoadDataFromCache(String key) at Microsoft.SharePoint.WebControls.BaseXmlDataSource.GetXmlDocument() at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetHierarchicalDocument(IHierarchicalDataSource ds) at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetHierarchicalXPathNavigator(IHierarchicalDataSource ds) at Microsoft.SharePoint.WebControls.SingleDataSource.GetXPathNavigatorInternal() at Microsoft.SharePoint.WebControls.SingleDataSource.GetXPathNavigator() at Microsoft.SharePoint.WebControls.SingleDataSource.GetXPathNavigator(IDataSource datasource, Boolean origin…
Blha Blha….. Really could not tell what’s going on, but If I add the same web-part from the UI (Using the Web Part Gallery) than it worked fine and my feed showed up in the web-part. After examining the properties of the working web-part in the debug mode, I noticed the web part has DataSourceString and ParameterBindings property set, MSDN has no documentation about it (or at least I could not find it) and setting those properties when adding RSS WebPart programmatically worked
Here is the full code snippet
RSSAggregatorWebPart rssViewer = new RSSAggregatorWebPart(); rssViewer.FeedUrl = "http://ketulpatel.wordpress.com/feed/"; rssViewer.ID = "rssFeed"; StringBuilder dataSourceString = new StringBuilder("<%@ Register TagPrefix=\"WebControls\" Namespace=\"Microsoft.SharePoint.WebControls\" Assembly=\"Microsoft.SharePoint, Version=220.127.116.11, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %>"); dataSourceString.Append("<%@ Register TagPrefix=\"WebPartPages\" Namespace=\"Microsoft.SharePoint.WebPartPages\" Assembly=\"Microsoft.SharePoint, Version=18.104.22.168, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %>"); dataSourceString.Append("<WebControls:XmlUrlDataSource runat=\"server\" AuthType=\"None\" HttpMethod=\"GET\">"); dataSourceString.Append("<DataFileParameters>"); dataSourceString.Append("<WebPartPages:DataFormParameter Name=\"RequestUrl\" ParameterKey=\"RequestUrl\" PropertyName=\"ParameterValues\"/>"); dataSourceString.Append("</DataFileParameters>"); dataSourceString.Append("</WebControls:XmlUrlDataSource>"); rssViewer.DataSourcesString = dataSourceString.ToString(); rssViewer.ParameterBindings = "<ParameterBinding Name=\"RequestUrl\" Location=\"WPProperty[FeedUrl]\"/>"; rssViewer.Title = "My Blog"; AddWebPart(web,rssViewer,"default.aspx","CenterColTop",0);
Value of DataSourceString is:
<%@ Register TagPrefix="WebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=22.214.171.124, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=126.96.36.199, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <WebControls:XmlUrlDataSource runat="server" AuthType="None" HttpMethod="GET"> <DataFileParameters> <WebPartPages:DataFormParameter Name="RequestUrl" ParameterKey="RequestUrl" PropertyName="ParameterValues"/> </DataFileParameters> </WebControls:XmlUrlDataSource>
Value of ParameterBindings is:
<ParameterBinding Name="RequestUrl" Location="WPProperty[FeedUrl]"/>