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


Prabhu RajaRank #861 · 2.6K reputationPosted Sep 9, 2011, 7:49 AM EDT
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"
ravi rayana2 reputationPosted Dec 20, 2011, 11:11 PM EST
VulpesRank #55 · 29.2K reputationPosted Dec 20, 2011, 11:43 PM EST
Marutharasu P50 reputationPosted Feb 9, 2014, 9:35 PM EST