Posts

Soap call from Controller

public static void Execute(string NTID)         {             HttpWebRequest request = CreateWebRequest();             XmlDocument soapEnvelopeXml = new XmlDocument();             soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""                          xmlns:urn=""urn:sap-com:document:sap:rfc:functions"">                 <soapenv:Header xmlns:wsa =""http://www.w3.org/2005/08/addressing"" >                    <wsa:Action>urn:sap-com:document:sap:rfc:functions:Z_WS_TRAIN_HIST:Z_GET_TRAIN_HISTRequest             ...

Favorite Powershell Scripts

Mock sitemap This simple script gives us an overview of all pages - we just need to clean up the bin and obj folder listings  - do some simple replaces and turn it into links or a sitemap It creates a list of all of the filetypes specified into an output text file Below I have specified on .aspx files but you could do something like .htm,asp,aspx instead to include multiple file types. Get-ChildItem D:\mydirectory\My.WebApplication -recurse -include *.aspx| ForEach-Object { $_.FullName } > D:\mydirectory\My.WebApplication\output.txt More Powershell Resources PowerShell Scripts Repository Stackify Power Shell Commands Cheatsheet

Dynamic Form

namespace MyApp {     /// <summary>     /// Summary description for RemotePost     /// </summary>     public class RemotePost     {        private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();         public string Url = "";         public string Method = "post";         public string FormName = "form1";         public void Add(string name, string value)         {             Inputs.Add(name, value);         }         public void Post()         {             System.Web.HttpContext.Current.Response.Clear();             System.Web.HttpContext.Current.Response.Write("<h...

Linq Exclude from separate list

 var urlList = new List<DisplayAssets>();    var assetsToExclude = (from a in db.DisplayAssets                 join h in db.Hardware_Assets on a.id equals h.displayId                 where h.assetId == hardwareid                 select a.id); var allAssets = db.DisplayAssets; var urls = allAssets.Where(x => !assetsToExclude.Contains(x.id));         urlList = urls.Select(a => new DisplayAssets()         {             locaterAddress  = a.locaterAddress,             assetType = a.assetType,             id = a.id         })         .ToList();

Return Generics ILIST

      public IList GetTeamcallSummary()        {            int currentmonth = DateTime.Today.Month;            int lastmonth = DateTime.Today.AddMonths(-3).Month;                    var calldata = (from c in db.calldetail_viw                where c.ConnectedDate.Value.Month >= lastmonth                      && c.ConnectedDate.Value.Month <= currentmonth                      && c.LocalName == "myaccountrep"                            group c by new { c.AssignedWorkGroup, month = c.ConnectedDate.Value.Month }                into g       ...

Form Collection 3 approaches

Here are 3 ways to get your values with a FormCollection object. public ActionResult SomeActionMethod ( FormCollection formCollection ) { //Cycling through the AllKeys foreach ( var key in formCollection . AllKeys ) { var value = formCollection [ key ]; } //By Each Key foreach ( var key in formCollection . Keys ) { var value = formCollection [ key . ToString ()]; } // Using the ValueProvider IValueProvider valueProvider = formCollection.ToValueProvider(); foreach (string key in formCollection.Keys) { ValueProviderResult result = valueProvider.GetValue(key); string value = result.AttemptedValue; } }

Linq and Lambda syntax

var jsonData = from user in users select new [] { user . Id . ToString (), user . Person . Lastname , user . Person . Firstname }; Alternatively, you can use the lambda syntax: var jsonData = users . Select ( user => new [] { user . Id . ToString (), user . Person . Lastname , user . Person . Firstname });