hi,
i want to get path of selected file using OpenFileDialog,
but its shown "File operation not permitted. Access to path is denied." error.
I have user following code and want to display full path in text box
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = false;dlg.Filter = "Video Files (*.mp4)|*.mp4|Video Files (*.mpeg)|*.mpeg|Video Files (*.wmv)|*.wmv";
dlg.FilterIndex = 1;
bool? retval = dlg.ShowDialog();
if (retval != null && retval == true)
{
UploadVideo(dlg.File.Name, dlg.File.OpenRead());
//string filePath = Path.GetDirectoryName(dlg.File.Name);
txtVideoPath.Text = dlg.File.Name;
}
Any idea how to get full path?
Loading

Marutharasu PPosted Feb 10, 2014, 2:35 AM
VulpesPosted Dec 21, 2011, 4:43 AM
ravi rayanaPosted Dec 21, 2011, 4:11 AM
Prabhu RajaPosted Sep 9, 2011, 11:49 AM
Try this
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = false;
dlg.InitialDirectory = "C:\\";
dlg.Filter = "Video Files (*.mp4)|*.mp4|Video Files (*.mpeg)|*.mpeg|Video Files (*.wmv)|*.wmv";
dlg.FilterIndex = 0;
dlg.RestoreDirectory = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
UploadVideo(dlg.FileName, dlg.OpenFile );
txtVideoPath.Text = dlg.FileName;
}
catch (Exception ex)
{
MessageBox.Show("Error: can not read file from disk.Original error: " + ex.Message);
}
}
---------------------------------
If this post helps you, then mark as "Correct Answer"