c# setting xmlns root attribute serialization

İf you want to  set xmlns attribute when serialization process you can  use XmlRoot attribute namespace .

[Serializable]

[XmlRoot(Namespace= @”http://schemas.microsoft.com/sharepoint/”) ]

public class Elements

{

public Elements()

{

}

private string _ID;

[XmlAttribute]

public string ID

{

get { return _ID; }

set { _ID = value; }

}

}

happy tips..

Advertisement

TaxonomyWebTaggingControl – Sharepoint

Hi guys , in this article i will tell you how to use TaxonomyWebTaggingControl . First of all i assume that you already define your terms and terms sets in your sharepoint managed meta data service.This control help us that show and set this terms for various purpose. Msdn says “A TaxonomyWebTaggingControl object is a Web control that can be added to a page so that a user can pick one or more taxonomy Term object from a specific TermSet object or from an entire TermStore object.”

First we register control in our page definition.

<%@ Register Assembly="Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    Namespace="Microsoft.SharePoint.Taxonomy" TagPrefix="cc1" %>

And control in the content like this

<cc1:TaxonomyWebTaggingControl ID="TaxonomyControl" runat="server" >
</cc1:TaxonomyWebTaggingControl>

At code behind we getting taxonomy store from metadataservice and set the control properties

Dont forget to add your libraries.

using Microsoft.SharePoint.Taxonomy;
using Microsoft.SharePoint;
And your code here
SPContext context = SPContext.Current;
SPSite site = context.Site;
TaxonomySession session = new TaxonomySession(site);
TermStore termStore = session.TermStores["Managed Metadata Service"]; //if you a custom meta service you should change name.
Group group = termStore.Groups["MyGroup"];
TermSet productsTermSet = group.TermSets["Genders"];

.the code above just getting metadata objects from service via using taxonomy entities.

In my code i am usign UserProfileService which has a user property named “Gender” means “Male,Female” which is defined in metadataservice. I am going to set TaxonomyWebTaggingControl (ID: TaxonomyControl) and get value from this control.

Bind the control with entities

TaxonomyControl.SspId.Add(termStore.Id);

TaxonomyControl.TermSetId.Add(productsTermSet.Id);

TaxonomyControl.IsAddTerms = true;

TaxonomyControl.AllowFillIn = true;

TaxonomyControl.IsMulti = false;

Setting data to control with userprofile object:


string
termName = service.GetUserPropertyByAccountName(loginName, ProfileProperties.Genders).GetSingleValue();// don’t worry about this line this is not in our concept.Just know this line getting value from UserProfileService as string.

TaxonomyControl.Text = string.Format(“{0}|{1}”, termName, productsTermSet.Terms[termName].Id.ToString());

TaxonomyWebTaggingControl has a propery named “Text” . You should set this property  “[Label] | [Guid]” format.
Set values into this control as pairs of labels and GUIDs. The delimiter between a label and a GUID is the | character. When using multiple values, delimit them with a ; character. Example: term1|12345678-1234-1234-1234-123456789012;term2|87654321-4321-4321-4321-210987654321

Getting data from control :

TaxonomyFieldValueCollection portfolioCountriesValues = new TaxonomyFieldValueCollection(String.Empty);

portfolioCountriesValues.PopulateFromLabelGuidPairs(TaxonomyControl.Text);

profile[ProfileProperties.Genders].Value=  portfolioCountriesValues[0].Label;

We are using TaxonomyFieldValueCollection class that help us parsing data.

For More info:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.taxonomywebtaggingcontrol.aspx

Happy codding…

Sharepoint List Type Numbers

Hi everybody here is the sharepoint list type id list.

List Id List Description
100 Generic list
101 Document library
102 Survey
103 Links list
104 Announcements list
105 Contacts list
106 Events list
107 Tasks list
108 Discussion board
109 Picture library
110 Data sources
111 Site template gallery
112 User Information list
113 Web Part gallery
114 List template gallery
115 XML Form library
116 Master pages gallery
117 No-Code Workflows
118 Custom Workflow Process
119 Wiki Page library
120 Custom grid for a list
130 Data Connection library
140 Workflow History
150 Gantt Tasks list
200 Meeting Series list
201 Meeting Agenda list
202 Meeting Attendees list
204 Meeting Decisions list
207 Meeting Objectives list
210 Meeting text box
211 Meeting Things To Bring list
212 Meeting Workspace Pages list
301 Blog Posts list
302 Blog Comments list
303 Blog Categories list
1100 Issue tracking

Bye now.

when CacheItemRemovedCallback is raised HttpContext.Current is null

CacheItemRemovedCallback shows users the value assigned to an item in the cache and then notifies them when the item is removed from the cache. It creates a RemovedCallback method, which uses the signature of the CacheItemRemovedCallback delegate, to notify users when the cache item is removed and uses theCacheItemRemovedReason enumeration to tell them why it was removed.But when you try to use cache with HttpContext.Current it encounter an object not set reference error.

Here is the solution.

Use :HttpRuntime.Cache instead of HttpContext.Current.Cache object

Example::

 public static void DropUser(string key, object value, CacheItemRemovedReason reason)
        {
            List<string> OnlineUserAccounts = null;
            if (HttpRuntime.Cache[CACHE_KEY] != null)
            {
                OnlineUserAccounts = (List<string>)HttpRuntime.Cache[CACHE_KEY];
                if (OnlineUserAccounts.Contains(key))
                {
                    OnlineUserAccounts.Remove(key);
 
                    HttpRuntime.Cache[CACHE_KEY] = OnlineUserAccounts;
                }
            }
        }
 
Happy Codding.