/// <summary> |
/// This will enable the Enterprise Keyowrds for the associated lists |
/// </summary> |
/// <param name="properties">from list event</param> |
private void EnableEnterpriseKeywords(SPListEventProperties properties) |
{ |
//get an instance of list to be enabled with keyword |
SPList list = properties.List; |
//get an instance of SPTaxonomy assembly |
Assembly taxonomyAssembly = Assembly.LoadWithPartialName("Microsoft.SharePoint.Taxonomy"); |
//get an instance of internal class for the keyword association |
Type listFieldSettings = taxonomyAssembly .GetType("Microsoft.SharePoint.Taxonomy.MetadataListFieldSettings"); |
//pass the list to the internal class's constructor |
object listSettings = listFieldSettings.GetConstructor(new Type[] { typeof(SPList) }) |
.Invoke(new object[] { list }); |
//get an instance of KW property and set the boolean |
listFieldSettings.GetProperty("EnableKeywordsField", BindingFlags.NonPublic | BindingFlags.Instance) .SetValue(listSettings, true, null); |
listFieldSettings.GetProperty("EnableMetadataPromotion", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(listSettings, true, null); |
//update the list listFieldSettings.GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Instance) .Invoke(listSettings, null); |
} |
Please format the above code J |
Friday, April 22, 2011
Add Enterprise Keywords Column Programmatically For SharePoint Lists
Monday, April 18, 2011
Performance Of SharePoint List Access Methods
P.S: The above data is extracted from Developer Dashboard, by enabling the SPMonitoredScope for each access mechanism.
Monday, April 4, 2011
Access Denied On IISReset
Problem:
“Access denied, you must be an administrator of the remote computer to use this command. Either have your account added to the administrator local group of the remote computer or to the domain administrator group”
This is a common problem for those who have just started SharePoint 2010 development on newly installed Windows Server 2008/Windows 7 OS. Though you have the administrator rights on the computer, the default security mechanism in the OS itself enable the UAC (User Access Control) to higher level which blocks certain activities from doing deliberatively. One of such situation causes the IISRESET command to be failed, reporting the above error.
Solution:
Set the UAC to “Never Notify” level and make sure that you Restart the computer. Now the problem solved J
Tuesday, March 29, 2011
SPWeb Vs SPSite Vs SPWebApplication
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
namespace MyFirstTest
{
class Program
{
static void Main(string[] args)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWebApplicationCollection webappcol = SPWebService.ContentService.WebApplications;
foreach (SPWebApplication webapp in webappcol)
{
Console.WriteLine("Web Application URL :" + webapp.Name);
foreach (SPSite site in webapp.Sites)
{
Console.WriteLine("Site Collection URL :" + site.Url);
Console.ReadKey();
foreach (SPWeb web in site.AllWebs)
{
Console.WriteLine("Site URL :" + web.Url);
Console.ReadKey();
}
}
}
});
}
}
}
OutPut:
Web Application URL : Sharepoint-80
Site Collection URL : http://cd-Home
Site URL : http://cd-Home
http://cd-Home/Test
http://cd-Home/Test/Inside
Note:Since I am getting the "site.AllWebs" property it will iterate through all the webs in the Site Collection
Try in your environment you can understand the difference.....
Monday, March 7, 2011
Error occurred in deployment step 'Activate Features': Invalid field name.
1. If you have already deployed the solution and you get the error on later attempt, then the declarative mark-up of Field definition/List Schema could be modified from the version you already deployed to the site. Because the content db is queried for a non-existent object, where at that point it throws an error.
2. Referencing site column(field) from content type/lists cannot be resolved by the deploying thread. Your feature will be structured as below. The referee column located in the “Elements” Module is referred from “Test ContentType” Module. On deployment the feature is activated in the following order.
3. The template/structure of the schema/field file is wrong.
2. For the latter case, the site column(field) should be already deployed in the site before it’s being used by any other module(Test ContentType). In order to do that you don’t need to go for another feature, but simply you can change the order in the feature. In this case, the deployable feature takes the following form.
3. For the third case, rectify the issue in the schema/fields file.
Thursday, February 3, 2011
Coping DLL from the Global Assembly Cache
Wednesday, February 2, 2011
Control Anonymous User from Accessing Application Pages
I came across a requirement where the SharePoint site should be enabled for the anonymous users in the meantime, they should be restricted to view from the application pages. So first my choice was ViewLockDownFeature, shipped with SharePoint 2007 STSADM. I thought I saved the time by just enabling the feature would solve me the problem. Yes it solved me the problem but it spawned me another problem where the feature blocks the anonymous users navigate to the blog entries, since the blog entries are accessing the Lists directly and get the page contents.
Sample Url of blog
../myblog/Lists/Categories/Category.aspx?CategoryId=2&Name=Category 2
Workaround 1:
Setting the policy at web.config level.
<configuration>
<location path="_layouts/viewlsts.aspx ">
<system.web>
<authorization>
<deny users="*"/>
</authorization>
</system.web>
</location>
</configuration>
For further information follow up here.
The problem in the above method is, if you want to block all the application pages and still wants the blog accessible to anonymous users, then you have to specify all the application page url.
Workaround 2:
Tweaking with Delegate control
SharePoint is a pool to play with delegate controls, where the winner is supposed to get a chunk of development time compared to other optional method.
Normally SharePoint delegate controls resides in Master page and Page layout as well as in Application Pages. First I delve into the delegate controls for the custom navigation control. This is the second time, where I observed that all the application pages are having the delegate control. So overriding the delegate control in the following manner will help you to implement your own policy to ranging from different user groups to different site, page and to url level.
public class AnonyousePolicy:UnsecuredLayoutsPageBase
{
protected override void OnLoad(EventArgs e)
{
if (System.Web.HttpContext.Current.Request.Url.PathAndQuery.IndexOf("_layouts/RedirectionModule/") > 0)
{
//Do Nothing as Anonymous users need to get that redirection available
}
else if (System.Web.HttpContext.Current.Request.Url.PathAndQuery.IndexOf("_layouts/", StringComparison.InvariantCultureIgnoreCase) > 0)
{
if (SPContext.Current.Web.CurrentUser == null)
{
// Anonymous user, prevent access
SPUtility.TransferToErrorPage("Anonymous users have no access to this page");
}
}
}
}
Conclusion : I feel the first method is a simple way to block the anonymous users, provided the accessibility is not restricted upon the user group and less number of application pages.
Second method is handy method is more flexible than the first method I hope !
Expect your feedback.