How will you use Selenium to upload a file?

If the file is on the same machine or in a mapped network drive, it is really straightforward: We need to type the "path" of the file in the FileUpload control. For example:

//Locate file selection input field 
WebElement uploadElement = driver.findElement(By.id(""));

// enter the file path onto the file-selection input field
uploadElement.sendKeys("C:\\myfile.txt");

// click the "UploadFile" button
driver.findElement(By.name("send")).click();