Asked by countrymeister
at 2024-07-08 04:21:42
Point:500 Replies:5 POST_ID:828938USER_ID:11836
Topic:
C# Programming Language;;.NET
I am copy a pdf file from Location A to Location B. After copying I want to open the file.
This gives me an error stating access to the file is denied.
private void OpenFile(string fileDirectory , string fileName)
{
try
{
string currFile = String.Format("{0}{1}", fileDirectory, fileName);
string path = System.IO.Directory.GetCurrentDirectory();
string newFile = String.Format("{0}{1}", path, fileName);
File.Copy(currFile, newFile, true);
FileAttributes currAttributes = File.GetAttributes(newFile);
File.SetAttributes(newFile, currAttributes | FileAttributes.ReadOnly);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.FileName = newFile;
process.Start();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message + "" + ex.StackTrace);
}
}
This gives me an error stating access to the file is denied.
private void OpenFile(string fileDirectory , string fileName)
{
try
{
string currFile = String.Format("{0}{1}", fileDirectory, fileName);
string path = System.IO.Directory.GetCurrentDirectory();
string newFile = String.Format("{0}{1}", path, fileName);
File.Copy(currFile, newFile, true);
FileAttributes currAttributes = File.GetAttributes(newFile);
File.SetAttributes(newFile, currAttributes | FileAttributes.ReadOnly);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.FileName = newFile;
process.Start();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message + "" + ex.StackTrace);
}
}