VS Snippets - auto-mate/CheatSheetWiki GitHub Wiki

Ctrl K+X Insert
shortcut name and tab x2 Insert
Ctrl K+B Add or find location

arrayLst
constClass
dirList
getSQL
interOp
msgboxAction
quit
selenium
shellProgram
shellProgramExt
sleep
toolTip
webQuery

Format

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Square Root MS Example</Title>
            <Shortcut>sqrt</Shortcut>
            <Description>Code snippet Square Root</Description>
            <Author>MS</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[double root = Math.Sqrt($Number$);]]>
            </Code>
            <Declarations>
              <Literal>
                <ID>Number</ID>
                <ToolTip>Choose the number you want the square root of.</ToolTip>
                <Default>16</Default>
              </Literal>
            </Declarations>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

CSharp

shellProgram

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Run Shell Program</Title>
            <Shortcut>shellProgram</Shortcut>
            <Description>Code snippet Run Shell Program</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
              System.Diagnostics.Process.Start("calc.exe");
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

msgboxAction

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Message Box Action</Title>
            <Shortcut>msgboxAction</Shortcut>
            <Description>Code snippet Message Box Action</Description>
            <Author>MS</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
              // confirm something
              DialogResult msg = MessageBox.Show("Prompt", "Header", MessageBoxButtons.OKCancel);
              if (msg.ToString() == "OK") {
              }                  
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

getSQL

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Get SQL Data</Title>
            <Shortcut>getSQL</Shortcut>
            <Description>Code snippet getSQL</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
            private string getSQL() {
                
                /* Example Get Encrypted Password From SQL*/
                
                string pw = "";

                System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
                con.ConnectionString = "Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;Integrated Security=SSPI;";  
                con.Open();                
                System.Data.SqlClient.SqlCommand cmd = con.CreateCommand();
                /* SQL TO PASS */
                cmd.CommandText = "SELECT CONVERT(varchar, DECRYPTBYPASSPHRASE('" +constants.passPhase + "', password)) from [YOUR_TABLE] WHERE LTRIM(RTRIM([YOUR_username_FIELD]))='"+ System.Environment.UserName +"'";
                System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
                
                while (dr.Read()) {             
                        pw = dr.GetValue(0).ToString().Trim();                  
                }
                con.Close();
                
                return pw;
            }
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

shellProgramExt

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>shellProgramExt</Title>
            <Shortcut>shellProgramExt</Shortcut>
            <Description>Code snippet shellProgramExt</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
            // Create process to run vbs script 
            System.Diagnostics.Process vs = new System.Diagnostics.Process();
            vs.StartInfo.RedirectStandardError = true;
            vs.StartInfo.RedirectStandardOutput = true;
            vs.StartInfo.FileName = "cscript";
            vs.StartInfo.WorkingDirectory = System.Environment.
                                            GetFolderPath(System.Environment.SpecialFolder.UserProfile) + 
                                            @"\AppData\Roaming\.....\";  
            vs.StartInfo.Arguments = script + " " + arg;
            vs.StartInfo.UseShellExecute = false;
            vs.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            vs.StartInfo.CreateNoWindow = true;
            // credentials
            vs.StartInfo.UserName = System.Environment.UserName; 
            vs.StartInfo.PasswordInClearText = getPassword();
            vs.StartInfo.Domain = "YOUR_DOMAIN";
            vs.Start();
            // Dont continue until vbs scriot is complete                
            vs.WaitForExit();

            
            // Read Output of Script
            ArrayList strShipData = new ArrayList();
            while (!vs.StandardOutput.EndOfStream)
            {
                strShipData.Add(vs.StandardOutput.ReadLine());
            }
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

constClass

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>constClass</Title>
            <Shortcut>constClass</Shortcut>
            <Description>Code snippet static class constants</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
              static class constants
              {
                  /* e.g. */
                  public const string con1   = "123456";
                  public const string con2   = "ABCDEFG";                      
                  public const string tmpDir = @"C:\Temp";

              }
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

toolTip

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>toolTip</Title>
            <Shortcut>toolTip</Shortcut>
            <Description>Code snippet toolTip</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
            /* RUN AFTER InitializeComponent(); */
            ToolTip tt001  = new ToolTip();
            // e.g. for label1
            tt001.SetToolTip(this.label1, "TOOL TIP TEXT");
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

webQuery

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>webQuery</Title>
            <Shortcut>webQuery</Shortcut>
            <Description>Code snippet webQuery</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
                // create web client to mange request
                System.Net.WebClient wc = new System.Net.WebClient();
                
                // Set webAddr
                string webAddr = "http://........php";

                // Set Method
                string method = "POST";
                
                // add Query string Examples
                wc.QueryString.Add("PostName01", YOUR_TEXT ); 
                wc.QueryString.Add("PostName02", YOUR_TEXT ); 
                
                // Send and Read Reply
                var reply = wc.UploadValues(webAddr, method, wc.QueryString);

                // Parse the returned data to a string.
                string dl = UnicodeEncoding.UTF8.GetString(reply);

              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

arrayLst

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>arrayLst</Title>
            <Shortcut>arrayLst</Shortcut>
            <Description>Code snippet arrayLst</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
            ArrayList arrLst = new ArrayList();
            arrLst.Add(YOUR_DATA);            
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

quit

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>quit</Title>
            <Shortcut>quit</Shortcut>
            <Description>Code snippet quit</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
              System.Environment.Exit(0);
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

sleep

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>sleep</Title>
            <Shortcut>sleep</Shortcut>
            <Description>Code snippet sleep 1 Sec</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
              Thread.Sleep(1000);
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

selenium

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>selenium</Title>
            <Shortcut>selenium</Shortcut>
            <Description>Code snippet selenium</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
              /*
              using System;
              using OpenQA.Selenium;
              using OpenQA.Selenium.Chrome;
              using System.Threading;
              using System.Collections.Generic;
              */

              /* ### SELENIUM SETUP ### */
              string downloadDir = args[0]; // Directory For any chrome downloads
              string chrmDrvDir  = args[1]; // Directory For the chrome driver
              string url         = args[2]; // URI to go to                 

              Console.WriteLine("Running..."); 

              ChromeOptions options = new ChromeOptions();
              options.AddArguments("--no-sandbox --start-fullscreen");
              options.AddUserProfilePreference("download.default_directory", downloadDir); 
              IWebDriver MyDriver = new ChromeDriver(chrmDrvDir, options, TimeSpan.FromMinutes(5) ); 

              // ### LOAD WEBPAGE ###                  
              MyDriver.Navigate().GoToUrl(url);
              

              // ### SOME ACTIONS
              MyDriver.SwitchTo().DefaultContent();
              MyDriver.SwitchTo().Frame(0);
              MyDriver.FindElements(By.ClassName("YOUR_CLASS_NAME"))[0].Click();
              MyDriver.FindElements(By.ClassName("YOUR_CLASS_NAME"))[0].FindElements(By.TagName("YOUR_TAG_NAME"))[1].Enabled;
              MyDriver.SwitchTo().Window(MyDriver.WindowHandles[1]); // POP UP
              MyDriver.FindElements(By.XPath("YOUR_X_PATH"))[0].Selected;

              // ### CLOSE SELENIUM
              MyDriver.Quit();

              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

dirList

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>dirList</Title>
            <Shortcut>dirList</Shortcut>
            <Description>Code snippet dirList</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
              string[] fileList = System.IO.Directory.GetFiles(@"C:\temp");
              int noOfFiles = fileList.Length;
              ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>

interOp

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>interOp</Title>
            <Shortcut>interOp</Shortcut>
            <Description>Code snippet interOp</Description>
            <Author>AH</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
          <Snippet>
            <Code Language="CSharp">
              <![CDATA[                  
    public class Win32
    {
        [DllImport("User32.dll")]
        public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
        [DllImport("User32.dll")]
        public static extern Int32 SetForegroundWindow(int hWnd);
        [DllImport("User32.dll")]
        public static extern Boolean EnumChildWindows(int hWndParent, Delegate lpEnumFunc, int lParam);
        [DllImport("User32.dll")]
        public static extern Int32 GetWindowText(int hWnd, StringBuilder s, int nMaxCount);
        [DllImport("User32.dll")]
        public static extern Int32 GetWindowTextLength(int hwnd);
        [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
        public static extern int GetDesktopWindow();
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern long SendMessage(IntPtr handle, int msg, int wparam, int x);
    }
    
    /* USE IN class Program e.g. */
    static void Main(string[] args) {
      IntPtr main = Win32Application.Win32.FindWindow("#32770", "About Notepad");
      IntPtr btn  = Win32Application.Win32.FindWindowEx(main ,IntPtr.Zero, "Button",null);
      long l = Win32Application.Win32.SendMessage(btn, 0x0201, 0x0, 0x0);
            l = Win32Application.Win32.SendMessage(btn, 0x0202, 0x0, 0x0);
      MessageBox.Show( Convert.ToString( btn )); }
    }   
    
                  ]]>
            </Code>
      </Snippet>
    </CodeSnippet>
</CodeSnippets>
⚠️ **GitHub.com Fallback** ⚠️