If anyone is wondering what is the correct data type to map between .NET and SQL this link would be a good reference. :)
http://msdn.microsoft.com/en-us/library/ms131092.aspx
Sunday, October 14, 2012
Friday, October 12, 2012
Finding out Primary Key Foreign Key Relationship
I have came across this script on the internet which actually read system table to find out the primary key foreign key relationship between the tables. It is really useful for me as the database I am currently exploring had lots of PK_FK relationship. I hope by sharing this information it would also be useful to someone else who needed to find out
SELECT fk.name 'FK Name', tp.name 'Parent table', cp.name, cp.column_id, tr.name 'Refrenced table', cr.name, cr.column_id FROM sys.foreign_keys fk INNER JOIN sys.tables tp ON fk.parent_object_id = tp.object_id INNER JOIN sys.tables tr ON fk.referenced_object_id = tr.object_id INNER JOIN sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id INNER JOIN sys.columns cp ON fkc.parent_column_id = cp.column_id AND fkc.parent_object_id = cp.object_id INNER JOIN sys.columns cr ON fkc.referenced_column_id = cr.column_id AND fkc.referenced_object_id = cr.object_id ORDER BY tp.name, cp.column_id
SELECT fk.name 'FK Name', tp.name 'Parent table', cp.name, cp.column_id, tr.name 'Refrenced table', cr.name, cr.column_id FROM sys.foreign_keys fk INNER JOIN sys.tables tp ON fk.parent_object_id = tp.object_id INNER JOIN sys.tables tr ON fk.referenced_object_id = tr.object_id INNER JOIN sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id INNER JOIN sys.columns cp ON fkc.parent_column_id = cp.column_id AND fkc.parent_object_id = cp.object_id INNER JOIN sys.columns cr ON fkc.referenced_column_id = cr.column_id AND fkc.referenced_object_id = cr.object_id ORDER BY tp.name, cp.column_id
Friday, November 18, 2011
How to enable search for custom help collection in sharepoint 2010
When you create a custom help collection in Sharepoint 2010, it is not searchable by default. There is some articles on internet which pointed out that "Sharepoint Foundation Search" Service needs to be enabled. Anyway this is only half of the story.
First you need to start the "Sharepoint Foundation Search" in Central Admin. Go to Application Management->Manage Services on Server. Once it started the service name will change to "Sharepoint Foundation Help Search"
After that you need to set permission for Help Collection. The help collection which is installed for farm wide installation can be found under http://yourcentraladmin/sites/help . This site is hidden. You have to key in the address manually. The help file you install will be safe under the list "Product Help" in this site. First you need to make sure users can have read permission to this site.
Go to Site Permission and you will find a HelpGroup. You can give "Read" permission to this help group and add NT Authority\Authenticated Users to help group. In central admin you might not be able to find all the domain users. Anyway instead of adding every user to this help group adding the NT Authority\Authenticated Users should be enough.
After giving the permission you might not be able to go back to help window and search the help collection right away. There is a backend job which would refresh the search service to reflect the permission settings.
Go to job monitor in Central Administration and search for the "Sharepoint Foundation Help Search". The service has a job name "SharePoint Foundation Search Refresh". Run that service then start searching the keywords for your help collection. You should be able to search the help file.
To create you own help collection you can use "Help Collection Builder" from http://www.blackcompass.net/Products/Default.aspx . They have documentation on how to create the help file as well.
First you need to start the "Sharepoint Foundation Search" in Central Admin. Go to Application Management->Manage Services on Server. Once it started the service name will change to "Sharepoint Foundation Help Search"
After that you need to set permission for Help Collection. The help collection which is installed for farm wide installation can be found under http://yourcentraladmin/sites/help . This site is hidden. You have to key in the address manually. The help file you install will be safe under the list "Product Help" in this site. First you need to make sure users can have read permission to this site.
Go to Site Permission and you will find a HelpGroup. You can give "Read" permission to this help group and add NT Authority\Authenticated Users to help group. In central admin you might not be able to find all the domain users. Anyway instead of adding every user to this help group adding the NT Authority\Authenticated Users should be enough.
After giving the permission you might not be able to go back to help window and search the help collection right away. There is a backend job which would refresh the search service to reflect the permission settings.
Go to job monitor in Central Administration and search for the "Sharepoint Foundation Help Search". The service has a job name "SharePoint Foundation Search Refresh". Run that service then start searching the keywords for your help collection. You should be able to search the help file.
To create you own help collection you can use "Help Collection Builder" from http://www.blackcompass.net/Products/Default.aspx . They have documentation on how to create the help file as well.
Wednesday, September 21, 2011
Adding Mapping to Managed Metadata Properties
I've been tasked to write script for configuring search filter for custom user profile properties to deploy to production environment. The powershell script below can do the job to configure the mapping.
$searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
$cat = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $searchapp -Identity People
$crawledproperty=Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $cat -Name "urn:schemas-microsoft-com:sharepoint:portal:profile:DrivingLicenseClass"
$managedproperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name "DrivingLicenseClass" -Type 1
New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty
$searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
$cat = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $searchapp -Identity People
$crawledproperty=Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $cat -Name "urn:schemas-microsoft-com:sharepoint:portal:profile:DrivingLicenseClass"
$managedproperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name "DrivingLicenseClass" -Type 1
New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty
Thursday, July 28, 2011
The Mystery of SPWeb.SiteGroups and SPWeb.Groups
I've spend two days to find out how to create groups which is partaining just to Subsite. Everytime I created a group using SPWeb.SiteGroups.Add the group is associated with the parent site rather than subsite.
From documentation I realize
SPWeb.SiteGroups is associated with SiteCollection
SPWeb.Groups is associated with Web
So I attempted SPWeb.Groups.Add. And I encounter the following error message.
“You cannot add a group directly to the Groups collection. You can add a group to the SiteGroups collection.”
Damn!
To create a group for subsite, you have to create site groups first. After creating site group you have to add association of the group with sub site.
Someone from MSDN forum kind enough to give me this solution. I am just sharing it again to save the headache of others.
Pay attention to web.AssociatedGroups.Add. Without this function the group will not be associated to the subsite. :)
//Add the group to the SPWeb web
//This will add the SPGroup to SiteCollection
web.SiteGroups.Add(groupName, owner, defaultuser, description);
//Associate de group to the SPWeb.
//This will add the SPGroup to left side quicklaunch of Manage Groups page
web.AssociatedGroups.Add(web.SiteGroups[groupName]);
web.Update();
//Assignment of the roles.
//This is the actual permission/role assignment of SPGroup
SPRoleAssignment assignment = new SPRoleAssignment(web.SiteGroups[groupName]);
SPRoleDefinition roleApp = web.RoleDefinitions["Contribute"];
assignment.RoleDefinitionBindings.Add(roleApp);
web.RoleAssignments.Add(assignment);
web.Update();
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/b6a7edda-e5fd-4a58-9273-e12705bec727
From documentation I realize
SPWeb.SiteGroups is associated with SiteCollection
SPWeb.Groups is associated with Web
So I attempted SPWeb.Groups.Add. And I encounter the following error message.
“You cannot add a group directly to the Groups collection. You can add a group to the SiteGroups collection.”
Damn!
To create a group for subsite, you have to create site groups first. After creating site group you have to add association of the group with sub site.
Someone from MSDN forum kind enough to give me this solution. I am just sharing it again to save the headache of others.
Pay attention to web.AssociatedGroups.Add. Without this function the group will not be associated to the subsite. :)
//Add the group to the SPWeb web
//This will add the SPGroup to SiteCollection
web.SiteGroups.Add(groupName, owner, defaultuser, description);
//Associate de group to the SPWeb.
//This will add the SPGroup to left side quicklaunch of Manage Groups page
web.AssociatedGroups.Add(web.SiteGroups[groupName]);
web.Update();
//Assignment of the roles.
//This is the actual permission/role assignment of SPGroup
SPRoleAssignment assignment = new SPRoleAssignment(web.SiteGroups[groupName]);
SPRoleDefinition roleApp = web.RoleDefinitions["Contribute"];
assignment.RoleDefinitionBindings.Add(roleApp);
web.RoleAssignments.Add(assignment);
web.Update();
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/b6a7edda-e5fd-4a58-9273-e12705bec727
Thursday, July 7, 2011
Scanning through tags and notes, comments and User profile data in Sharepoint 2010
I've come across a task where by I need to write a timer job to scan through User profile data and all the social networking tags and notes to policing whether any user has put in any vulgarities or inappropriate comments. After going through the API and some of the testing on my own this is a small prototype of my findings. The program can tell which user has made what kind of changes for all these data. If anyone out there looking for something similar to what I needed to be done I guess this would help someone's live a little easier. :)
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.Office.Server.SocialData;
namespace UserProfileChanges
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://yourserver"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager profileManager =
new UserProfileManager(context);
// this gets some subset of changes to a user profile
DateTime startDate =
DateTime.UtcNow.Subtract(TimeSpan.FromDays(5));
UserProfileChangeQuery changeQuery =
new UserProfileChangeQuery(false, true);
UserProfileChangeToken changeToken =
new UserProfileChangeToken(startDate);
changeQuery.ChangeTokenStart = changeToken;
changeQuery.Anniversary = false;
changeQuery.SingleValueProperty = true;
changeQuery.MultiValueProperty = true;
changeQuery.DistributionListMembership = false;
changeQuery.SiteMembership = false;
changeQuery.UpdateMetadata = true;
UserProfileChangeCollection changes =
profileManager.GetChanges(changeQuery);
foreach (UserProfileChange change in changes)
{
Console.WriteLine("Changes occurs at "+change.EventTime.ToString());
if (change is UserProfilePropertyValueChange)
{
UserProfilePropertyValueChange propertyChange =
(UserProfilePropertyValueChange)change;
if (propertyChange.ChangeType.ToString() == "Metadata")
{
Console.WriteLine("Change Type " + propertyChange.ChangeType.ToString());
Console.WriteLine("Name " + propertyChange.ProfileProperty.Name);
Console.WriteLine("Account Name" + propertyChange.AccountName);
Microsoft.Office.Server.UserProfiles.UserProfile u = profileManager.GetUserProfile(propertyChange.AccountName);
Console.WriteLine("Property Value " + u[propertyChange.ProfileProperty.Name].ToString());
Console.WriteLine();
Console.WriteLine();
}
}
}
UserProfileManager myUserProfileManager = new UserProfileManager(context);
foreach (UserProfile myUserProfile in myUserProfileManager)
{
SocialTagManager mySocialTagManager = new SocialTagManager(context);
SocialTag[] tags = mySocialTagManager.GetTags(myUserProfile);
Console.WriteLine("Tags for user:");
foreach (SocialTag tag in tags)
{
Console.WriteLine(tag.Term.Name + ": " + tag.Url);
Console.WriteLine(tag.Owner.DisplayName);
}
SocialCommentManager mySocialCommentManager = new SocialCommentManager(context);
SocialComment[] comments = mySocialCommentManager.GetComments(myUserProfile);
Console.WriteLine("Comments for user:");
foreach (SocialComment comment in comments)
{
Console.WriteLine(comment.Url + ": " + comment.Comment);
Console.WriteLine(comment.Owner.DisplayName);
}
}
Console.Read();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.Office.Server.SocialData;
namespace UserProfileChanges
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://yourserver"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager profileManager =
new UserProfileManager(context);
// this gets some subset of changes to a user profile
DateTime startDate =
DateTime.UtcNow.Subtract(TimeSpan.FromDays(5));
UserProfileChangeQuery changeQuery =
new UserProfileChangeQuery(false, true);
UserProfileChangeToken changeToken =
new UserProfileChangeToken(startDate);
changeQuery.ChangeTokenStart = changeToken;
changeQuery.Anniversary = false;
changeQuery.SingleValueProperty = true;
changeQuery.MultiValueProperty = true;
changeQuery.DistributionListMembership = false;
changeQuery.SiteMembership = false;
changeQuery.UpdateMetadata = true;
UserProfileChangeCollection changes =
profileManager.GetChanges(changeQuery);
foreach (UserProfileChange change in changes)
{
Console.WriteLine("Changes occurs at "+change.EventTime.ToString());
if (change is UserProfilePropertyValueChange)
{
UserProfilePropertyValueChange propertyChange =
(UserProfilePropertyValueChange)change;
if (propertyChange.ChangeType.ToString() == "Metadata")
{
Console.WriteLine("Change Type " + propertyChange.ChangeType.ToString());
Console.WriteLine("Name " + propertyChange.ProfileProperty.Name);
Console.WriteLine("Account Name" + propertyChange.AccountName);
Microsoft.Office.Server.UserProfiles.UserProfile u = profileManager.GetUserProfile(propertyChange.AccountName);
Console.WriteLine("Property Value " + u[propertyChange.ProfileProperty.Name].ToString());
Console.WriteLine();
Console.WriteLine();
}
}
}
UserProfileManager myUserProfileManager = new UserProfileManager(context);
foreach (UserProfile myUserProfile in myUserProfileManager)
{
SocialTagManager mySocialTagManager = new SocialTagManager(context);
SocialTag[] tags = mySocialTagManager.GetTags(myUserProfile);
Console.WriteLine("Tags for user:");
foreach (SocialTag tag in tags)
{
Console.WriteLine(tag.Term.Name + ": " + tag.Url);
Console.WriteLine(tag.Owner.DisplayName);
}
SocialCommentManager mySocialCommentManager = new SocialCommentManager(context);
SocialComment[] comments = mySocialCommentManager.GetComments(myUserProfile);
Console.WriteLine("Comments for user:");
foreach (SocialComment comment in comments)
{
Console.WriteLine(comment.Url + ": " + comment.Comment);
Console.WriteLine(comment.Owner.DisplayName);
}
}
Console.Read();
}
}
}
}
Sunday, June 6, 2010
WCF: HTTP 407 Proxy Authentication Required
This error is really a big hassle for my web service program in our company. Our company use proxy and my program cannot go through if the proxy setting is being checked on the client PC. It took me quite awhile to research on how to resolve this issue until I come across this lovely article.. This really resolves the issue.
http://www.mikebevers.be/blog/2009/06/wcf-http-407-proxy-authentication-required/
I just simply need to add this in my app.config file
<system.net>
<defaultProxy useDefaultCredentials="true">
</system.net>
And as for WCF configuration we can keep the two attritubes
bypassProxyOnLocal="false"
useDefaultWebProxy="true"
if we want to enforce proxy on the web service
If we want to bypass proxy then we have to change it to
bypassProxyOnLocal="true"
useDefaultWebProxy="false"
And the solution will simply works like a charm. ;)
http://www.mikebevers.be/blog/2009/06/wcf-http-407-proxy-authentication-required/
I just simply need to add this in my app.config file
<system.net>
<defaultProxy useDefaultCredentials="true">
</system.net>
And as for WCF configuration we can keep the two attritubes
bypassProxyOnLocal="false"
useDefaultWebProxy="true"
if we want to enforce proxy on the web service
If we want to bypass proxy then we have to change it to
bypassProxyOnLocal="true"
useDefaultWebProxy="false"
And the solution will simply works like a charm. ;)
Subscribe to:
Posts (Atom)