Hi nirmal90,
Add two Button controls and one OpenFileDialog and one FolderBrowserDialog in the page.
OpenFileDialog will be used to select file and FolderBrowserDialog will used to select the folder to save the file.
Then write the code in the Button click event.
Namespaces
C#
using System.IO;
VB.Net
Imports System.IO
Code
C#
private void btnBrowse_Click(object sender, EventArgs e)
{
openFileDialog1.Multiselect = false;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = Path.GetFileName(openFileDialog1.FileName);
string filePath = openFileDialog1.FileName;
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
string newFileName = Path.GetFileNameWithoutExtension(openFileDialog1.FileName) + ".cnc";
File.Copy(openFileDialog1.FileName, Path.Combine(folderBrowserDialog1.SelectedPath, newFileName));
MessageBox.Show("File Saved successfully.", "", MessageBoxButtons.OK);
}
}
VB.Net
Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
openFileDialog1.Multiselect = False
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Dim fileName As String = Path.GetFileName(openFileDialog1.FileName)
Dim filePath As String = openFileDialog1.FileName
End If
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
If folderBrowserDialog1.ShowDialog() = DialogResult.OK Then
Dim newFileName As String = Path.GetFileNameWithoutExtension(openFileDialog1.FileName) & ".cnc"
File.Copy(openFileDialog1.FileName, Path.Combine(folderBrowserDialog1.SelectedPath, newFileName))
MessageBox.Show("File Saved successfully.", "", MessageBoxButtons.OK)
End If
End Sub