Split String Based On Upper Case

string ConvertToWord(string value)
{
    StringBuilder builder = new StringBuilder();
    foreach (char c in value)
    {
        if (Char.IsUpper(c) && builder.Length>0)
        {
            builder.Append(' ');
        }

        builder.Append(c);
    }

    string result = builder.ToString();
    return result;
}


//Usage:
string beforeConvert = "IAmAGoodBoy";
string afterConvert = ConvertToWord(beforeConvert); //I Am A Good Boy

Access Phonebook from Android App

package com.imslbd.ussdapp;

import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void sendMessage(View view) {
        pickContact();
    }

    static final int PICK_CONTACT_REQUEST = 1;  // The request code

    private void pickContact() {
        Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
        pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
        startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // Check which request it is that we're responding to
        if (requestCode == PICK_CONTACT_REQUEST) {
            // Make sure the request was successful
            if (resultCode == RESULT_OK) {
                // Get the URI that points to the selected contact
                Uri contactUri = data.getData();
                // We only need the NUMBER column, because there will be only one row in the result
                String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER};

                // Perform the query on the contact to get the NUMBER column
                // We don't need a selection or sort order (there's only one result for the given URI)
                // CAUTION: The query() method should be called from a separate thread to avoid blocking
                // your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
                // Consider using CursorLoader to perform the query.
                Cursor cursor = getContentResolver()
                        .query(contactUri, projection, null, null, null);
                cursor.moveToFirst();

                // Retrieve the phone number from the NUMBER column
                int column = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
                String number = cursor.getString(column);
                EditText etPhone= (EditText) findViewById(R.id.mymessage);
                etPhone.setText(number);
                // Do something with the phone number...
            }
        }
    }
}

Android Button Click Basic

        Button myButton= (Button) findViewById(R.id.mybutton);
        myButton.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                // Perform action on click
                EditText mytextbox= (EditText) findViewById(R.id.mytextbox);
                mytextbox.setText("Hello World");
            }
        });

Client-Server File Handling Technique

//Server side
[ValidateInput(false)]
[HttpPost]
public JsonResult ReceiveAudio()
{
    try
    {
        foreach (string f in Request.Files.AllKeys)
        {
            var file = Request.Files[f];
            string fileName = file.FileName.ToString();
        }

        return Json("success");
    }
    catch (Exception Ex)
    {

    }
}

Recursively enumerate files within a directory

private void SearchVoiceFiles(string MainDirectoryPath)
{
    try
    {
        foreach (string dir in Directory.GetDirectories(MainDirectoryPath))
        {
            foreach (string file in Directory.GetFiles(dir))
            {
                string fileName = System.IO.Path.GetFileName(file);
                string fileExtenstion = Path.GetExtension(file);
                MessageBox.Show(fileExtenstion);
            }

            SearchVoiceFiles(dir);
        }
    }
    catch (System.Exception)
    {
        throw;
    }
}

Upload file from WinForm application to server

using BizArk.Core.Web; // http://bizark.codeplex.com/
var response = WebHelper.MakeRequest
                  ("http://Domain.com/Home/ReceiveAudio/",
                    new
                       {
                          wavFile = new FileInfo(e.FullPath)
                          //Test = "Hello",
                          //File1 = new UploadFile(@"text\plain", "file1.txt", 
                                   new MemoryStream(Encoding.UTF8.GetBytes("Hello "))),
                          //File2 = new FileInfo("MyFile.txt")
                        });

var result = response.ResultToString();

Working with FileSystemWatcher Class

private void ToggleMonitor(object sender, EventArgs e)
{
    // Create a new FileSystemWatcher object.
    FileSystemWatcher fsWatcher = new FileSystemWatcher();
    switch (btnToggleMonitor.Text)
    {
        //Start Monitoring…
        case startMonitoring:
            if (!txtMonitoringPath.Text.Equals(String.Empty))
            {
                fsWatcher.Path = txtMonitoringPath.Text;
                        
                // Set File Type Filter.
                fsWatcher.Filter = "*.*" or  "*.txt"

                // Monitor files and subdirectories.
                fsWatcher.IncludeSubdirectories = true;


                // Monitor all changes specified in the NotifyFilters.
                fsWatcher.NotifyFilter = NotifyFilters.Attributes |
                                            NotifyFilters.CreationTime |
                                            NotifyFilters.DirectoryName |
                                            NotifyFilters.FileName |
                                            NotifyFilters.LastAccess |
                                            NotifyFilters.LastWrite |
                                            NotifyFilters.Security |
                                            NotifyFilters.Size;
                        
                fsWatcher.EnableRaisingEvents = true;
                       
                // Raise Event handlers.
                fsWatcher.Changed += new FileSystemEventHandler(OnChanged);
                fsWatcher.Created += new FileSystemEventHandler(OnCreated);
                fsWatcher.Deleted += new FileSystemEventHandler(OnDeleted);
                fsWatcher.Renamed += new RenamedEventHandler(OnRenamed);
                fsWatcher.Error += new ErrorEventHandler(OnError);

                btnToggleMonitor.Text = stopMonitoring;
                txtMonitoringPath.Enabled = false;
                txtFileType.Enabled = false;
            }
            break;

        // Stop Monitoring…
        case stopMonitoring:
        default:
            fsWatcher.EnableRaisingEvents = false;
            fsWatcher = null;
            btnToggleMonitor.Text = startMonitoring;
            txtMonitoringPath.Enabled = true;
            txtFileType.Enabled = true;
            break;
    }
}






 
// FileSystemWatcher – OnCreated Event Handler
public void OnCreated(object sender, FileSystemEventArgs e)
{
    // Add event details in listbox.
    this.Invoke((MethodInvoker)delegate { textbox.text(e.FullPath, e.ChangeType); });
}

// FileSystemWatcher – OnChanged Event Handler
public void OnChanged(object sender, FileSystemEventArgs e)
{
    //Do something.
}


// FileSystemWatcher – OnRenamed Event Handler
public void OnRenamed(object sender, RenamedEventArgs e)
{
     System.Threading.Thread.Sleep(6000);
     string oldPath = e.OldFullPath;
     string newPath = e.FullPath;
     string oldName = e.OldName;
     string newName = e.Name;
}

// FileSystemWatcher – OnDeleted Event Handler
public void OnDeleted(object sender, FileSystemEventArgs e)
{
//Do something
}

// FileSystemWatcher – OnError Event Handler
public void OnError(object sender, ErrorEventArgs e)
{
e.GetException().Message
}

Periodically send ajax request to server from JavaScript

<script>
    function executeQuery() {
        $.ajax({
            url: 'http://localhost:54802/Calls/CheckNewVoices/',
            type: 'POST',
            data: "{'lastcheckdatetime':'" + lastCheckDateTime + "'}",
            dataType: 'json',
            contentType:'application/json; charset=utf-8',
            success: function (response) {
                lastCheckDateTime = response.lastcheckdatetime;
                console.log(lastCheckDateTime);
                var files = response.files;
                files.forEach(function (file, index) {
                    //Do something
                });
                setTimeout(executeQuery, 30000); //Call after 30 seconds.
            }
        });
    }

    $(function () {
        setTimeout(executeQuery, 30000); //Call after 30 seconds.
    });
</script>

ASP.NET web.config settings for large file uploading

<configuration>
     <appSettings>
	….. 
     </appSettings>
  
     <system.web>
          <compilation debug="true" targetFramework="4.5"/>
          <httpRuntime targetFramework="4.5" 
                       executionTimeout="1000" 
                       maxRequestLength="214748364" 
                       useFullyQualifiedRedirectUrl="false" 
                       minFreeThreads="8" 
                       minLocalRequestFreeThreads="4" 
                       appRequestQueueLimit="100" />
     </system.web>

     <connectionStrings>
        ….
     </connectionStrings>
  
     <system.webServer>
          <validation validateIntegratedModeConfiguration="false" />
          <handlers>
              <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
              <remove name="OPTIONSVerbHandler" />
              <remove name="TRACEVerbHandler" />
              <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*"   
                   type="System.Web.Handlers.TransferRequestHandler"  
                   preCondition="integratedMode,runtimeVersionv4.0" />
           </handlers>
           <security>
               <requestFiltering>
                   <requestLimits maxAllowedContentLength="1073741824" />
               </requestFiltering>
           </security>
       </system.webServer>
    
     <runtime>
        ….
     </runtime>
</configuration>