Wednesday 22 May 2013

Hide Multiple Upload link in SharePoint 2010

To hide the  “Upload Multiple Files..” link and from the ribbon we should add the below mentioned script in my CSS file (custom CSS file used of my master page). This will hide for all documents libraries for which this CSS is applied.

#ctl00_PlaceHolderMain_UploadDocumentSection_ctl03_UploadMultipleLink, #Ribbon\.Documents\.New\.AddDocument\.Menu\.Upload\.UploadMultiple-Menu32
{
         display: none; 
}

Wednesday 5 September 2012

Writing/Reading XML

Writing to XML
            XmlTextWriter writer = new XmlTextWriter("C:/TEMP/product.xml", System.Text.Encoding.UTF8);
            writer.WriteStartDocument(true);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartElement("Properties");
            createNode("model", "modelS", writer);
            createNode("supplier", "x", writer);
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Close();
Helper Method
private static void createNode(string key, string value, XmlTextWriter writer)
        {
            writer.WriteStartElement(key);
            writer.WriteString(value);
            writer.WriteEndElement();
        }
Reading XML
XmlDataDocument xmldoc = new XmlDataDocument();
            XmlNodeList xmlnode;
            int i = 0;
            string str = null;
            FileStream fs = new FileStream("C:/TEMP/product.xml", FileMode.Open, FileAccess.Read);
            xmldoc.Load(fs);
            xmlnode = xmldoc.GetElementsByTagName("Properties")[0].ChildNodes;
            for (i = 0; i <= xmlnode.Count - 1; i++)
            {
                str = xmlnode[i].Name +" | "+xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
                Console.WriteLine(str);
            }
XML Pattern

Monday 30 July 2012

Workaround: Calling a JavaScript Function from a HyperLinkField in a GridView or SPGridView

If you place a HyperLinkField in a GridView and link it to a JavaScript function, then it doesn't work properly. The problem is that the URL specified by the HyperLinkField'sNavigateUrl fails to render when you use a JavaScript reference (such as "Javascript:func();") rather than a standard URL.


As a workaround, we can use the RowDataBoundEvent to prepare a proper call to the JavaScript function. To make this work, while assigning the value we should give "Javascript." (with a period) instead of"Javascript:" (with a colon)


void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
//if it is not DataRow return.
if (e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
//Loop thru the cells changing the "." to ":" in hyperlink navigate URLs
for (int i = 0; i < e.Row.Cells.Count; i++)
{
TableCell td = e.Row.Cells[i];
if (td.Controls.Count > 0 && td.Controls[0] is HyperLink)
{
HyperLink hyperLink = td.Controls[0] as HyperLink;
string navigateUrl = hyperLink.NavigateUrl.ToLower();
hyperLink.NavigateUrl = hyperLink.NavigateUrl.Replace(
hyperLink.NavigateUrl.Substring(
navigateUrl.IndexOf("javascript."), "javascript.".Length),
"javascript:");
}
}
}

Wednesday 4 July 2012

Get/Set Values for Managed MetaData Field

Get Terms from the Field:
TaxonomyField commodityGrpFld = (TaxonomyField)web.Fields[“FieldName”];
       // get the Term Store ID from the field
       Guid commodityGrptermStoreId = commodityGrpFld.SspId;
       // Open a taxonomysession and get the correct termstore
       TaxonomySession session = new TaxonomySession(oSite);
       TermStore termStore = session.TermStores[commodityGrptermStoreId];               
       #region get terms from commodity termset
       try
       {
           TermSet termSetCommodity = termStore.GetTermSet(commodityGrpFld.TermSetId);                   
           if (termSetCommodity != null)
           {
               TermCollection CommodityTermColl = termSetCommodity.Terms;
               ArrayList commodityList = new ArrayList();
               foreach (Term commTerm in CommodityTermColl)
               {
                   commodityList.Add(commTerm.Name);
               }
//binding to listbox
               lbCommodityGrp.DataSource = commodityList;
               lbCommodityGrp.DataBind();
            }
        }
        catch (Exception)
        { }
        #endregion
Update the Item value for Managed Metadata field:
TaxonomyField taxoField_Commodity =spfile.Item.Fields[[“FieldName”] as TaxonomyField;
        TaxonomySession taxoSession = new TaxonomySession(oSite);
        TermStore store = taxoSession.TermStores[taxoField_Commodity.SspId];
        TermSet termSet = store.GetTermSet(taxoField_Commodity.TermSetId);
        if (taxoField_Commodity.AllowMultipleValues)
        {                                           
          TermCollection terms = termSet.GetAllTerms();
          List<string> taxonomyValueList = new List<string>();
          foreach (ListItem item in lbCommodityGrp.Items)
          {
            if (item.Selected)
            {
              taxonomyValueList.Add(item.Value);
            }
          }
          TaxonomyFieldValueCollection fieldValues = new TaxonomyFieldValueCollection(taxoField_Commodity);
          foreach (Term term in terms)
          {
             if (taxonomyValueList.Contains(term.Name))
             {
                TaxonomyFieldValue fieldValue = new TaxonomyFieldValue(taxoField_Commodity);
                fieldValue.TermGuid = term.Id.ToString();
                fieldValue.Label = term.Name;
                fieldValues.Add(fieldValue);
             }
          }
          taxoField_Commodity.SetFieldValue(spfile.Item, fieldValues);
       }
Get the Item value for Managed Metadata field:
                We need to convert the item value to TaxonomyFieldValueCollection

Monday 2 July 2012

Using SharePoint 2010 Content Organizer to Route Documents

This video walks through the process of uploading, saving, and routing documents based on content type metadata values by levereging Microsoft SharePoint Server 2010 Content Organizer feature.

http://sharepointquester.com/2012/03/06/how-to-route-documents-based-on-metadata-using-the-content-organizer-feature/