Wednesday, 25 September 2013


Direct call enum method


 public enum SearchScopes
    {
        WIP,
        Published,
        Archived,
        Obsolete,
        MILGeneral,
        LRGeneral,
        NLRGeneral
    }

refer by

string value=  SearchScopes.WIP;
Set  Enum method

public enum ESWTaskWorkFlowMap
    {
        [Description("ID")]
        ID,
        [Description("Task Number")]
        TaskNumber,
        [Description("Task Content No")]
        TaskContentNo,
        [Description("Task_x0020_Content_x0020_No")]
        TaskContentNoIn,
        [Description("Task Content Version")]
        TaskContentVersion,
        [Description("Task_x0020_Content_x0020_Version")]
        TaskContentVersionInt,
        [Description("Task Content Title")]
        TaskContentTitle,
        [Description("Task_x0020_Content_x0020_Title")]
        TaskContentTitleIn,
        [Description("Task Sequence")]
        TaskSequence,
        [Description("Task Applicability")]
        TaskApplicability,
        [Description("Task_x0020_Applicability")]
        TaskApplicabilityInt,
        [Description("Task_x0020_SubWorkflow_x0020_Map")]
        TaskSubWorkflowMapInt
    }


 public static string GetDescription(this Enum value)
        {
            if (value != null)
            {
                Type type = value.GetType();
                string name = Enum.GetName(type, value); if (name != null)
                {
                    FieldInfo field = type.GetField(name);
                    if (field != null)
                    {
                        DescriptionAttribute attr =
                         Attribute.GetCustomAttribute(field,
                         typeof(DescriptionAttribute)) as DescriptionAttribute;
                        if (attr != null)
                        {
                            return attr.Description;
                        }
                    }
                }
            }
            return null;
        }


string value=  ESWTaskWorkFlowMap.TaskNumber.getdescription();

result=Task Number
Batch Update


 public void SaveListData()
        {
            string batchOutput = string.Empty;
            using (new SPMonitoredScope("SaveWorkflowMapData"))
            {
                string batch = string.Empty;
               
               
                    SPList contentList = taskActivityWeb.Lists.TryGetList(Convert.ToString(taskList, CultureInfo.InvariantCulture));
                    if (contentList != null)
                    {
                        string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                        "<ows:Batch OnError=\"Return\">{0}</ows:Batch>";
                        string methodFormat = string.Empty;
                        if (SourceListItemCollection!= null && (SourceListItemCollection!> 0)
                        {
                            foreach (SPListItem WorkflowMapData in SourceListItemCollection)
                            {
                             
                                     
                                         
                                            methodFormat += String.Format(CultureInfo.InvariantCulture, "<Method ID=\"{0}\"><SetList>{1}</SetList><SetVar Name=\"Cmd\">Save</SetVar><SetVar Name=\"ID\">New</SetVar>", counter, DestinationList.ID);
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWSiteColumns.Title.GetDescription() + "\">" + taskNumber + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskContentNoIn.GetDescription() + "\">" + Convert.ToString(WorkflowMapData[ESWTaskWorkFlowMap.TaskContentNoIn.GetDescription()], CultureInfo.InvariantCulture) + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskContentVersionInt.GetDescription() + "\">" + Convert.ToInt32(WorkflowMapData[ESWTaskWorkFlowMap.TaskContentVersionInt.GetDescription()], CultureInfo.InvariantCulture) + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskContentTitleIn.GetDescription() + "\">" + Convert.ToString(hashWorkflowData[ESWTaskWorkFlowMap.TaskContentTitleIn.GetDescription()], CultureInfo.InvariantCulture) + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskSubWorkflowMapInt.GetDescription() + "\">" + subWorflowMap + "</SetVar>";
                                            methodFormat += "<SetVar Name=\"urn:schemas-microsoft-com:office:office#" + ESWTaskWorkFlowMap.TaskApplicabilityInt.GetDescription() + "\">" + 1 + "</SetVar>";
                                            methodFormat += "</Method>";
                                         
                                     
                            }
                           
                                batch = string.Format(CultureInfo.InvariantCulture, batchFormat, methodFormat);
                                oWeb.AllowUnsafeUpdates = true;
                                batchOutput = taskActivityWeb.ProcessBatchData(batch);
                                oWeb.AllowUnsafeUpdates = false;
                             
                                for (int i = 0; i < SourceListItemCollection.Count; i++)
                                {

                                   int savedlistitemID=Convert.ToInt32(GetResultsId(batchOutput)[i].InnerText, CultureInfo.InvariantCulture);
                                }
                         
                        }
                    }
                 
                }
             
            }
        }


        public static XmlNodeList GetResultsId(string batchOutput)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(batchOutput);
            return xmlDocument.GetElementsByTagName("ID");
        }

filter User Field in sharepoint list with unique value with out  name duplicate



<Eq>
                                        <FieldRef Name='{0}' LookupId='TRUE'/>
                                        <Value Type='User'>"+Spuser.ID+"</Value>
                                    </Eq>
Split string  with comma

 List<string> value = inputValue.Trim().ToUpperInvariant().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(r => !string.IsNullOrEmpty(r)).Select(d => d.Trim()).Distinct().ToList();
                    return String.Join(",", value.ToArray());

Get List string with comma using linq


string noProficiencyLevelForActivity = String.Join(",", noAccessDocumentsList.Select(p => p.ToString()).ToArray());
Dropdown selected value in jquery or javascript

$(document).ready(function () {
        $('#<%=drpfilterview.ClientID%>').change(function () {
            var SelectedView = $(this).find('option').filter(':selected').text();
           alert(SelectedView )
        });

    });
Linq Example


Linq

List<string> NotStartedCount = statusCollection.AsEnumerable().Where(f => f != null && f.ToUpperInvariant().Contains(TaskActivityStatus.NotStarted.GetDescription().ToUpperInvariant())).Select(d => d.ToString()).ToList<string>();
                                    List<string> CompletedCount = statusCollection.AsEnumerable().Where(f => f != null && f.ToUpperInvariant().Contains(TaskActivityStatus.Complete.GetDescription().ToUpperInvariant())).Select(d => d.ToString()).ToList<string>();



  pendingSubMapStatusCollection = activitypendingSubMapCollection.GetDataTable().AsEnumerable().Where(d => d != null
                                        && Convert.ToString(d[ESWTaskActivtiy.TaskActivityStatusInt.GetDescription()], CultureInfo.InvariantCulture) != null)
                                        .Select(h => Convert.ToString(h[ESWTaskActivtiy.TaskActivityStatusInt.GetDescription()], CultureInfo.InvariantCulture)).ToList<string>();


List<string> discUser = GetUsers.AsEnumerable().Where(d => d != null
                                                && employeetable.AsEnumerable().Any(f => f != null
                                                && Convert.ToString(f["ClockId"], CultureInfo.InvariantCulture).ToUpperInvariant().Equals(Convert.ToString(d["AccountName"], CultureInfo.InvariantCulture).ToUpperInvariant())))
                                               .Select(h => Convert.ToString(h["AccountName"], CultureInfo.InvariantCulture)).ToList<string>();