"Access is denied" error for opening documents
I tried to create the Open document method, but I got "Access is denied" error message. I checked the folder and files whether the security is executable, and it seems to be ok. Here is the code:
public void OpenDoc(string myDocumentsPath,
string fileName)
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.FileName = myDocumentsPath + fileName;
myProcess.StartInfo.Verb = "Open";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
}
else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(e.Message +
". You do not have permission to open this file.");
}
}
If you find something is wrong, please let me know.
Thank you for your help,
|