Page 1 of 1

C# Access Denied

Posted: Sat Feb 16, 2008 2:32 pm
by Aumaan Anubis
I'm trying to write something in C#, and the filestream is supposed to access a certain folder. The code is...

Code: Select all

FileStream stream = new FileStream("C:\\Documents and Settings\\***** *****\\Desktop\\Test Folder", FileMode.Open);
But everytime I try, I get the same error...

Image

However, I can open another file with a different application, though it's in the same folder as the one that won't allow my program access.

Any solutions?

Posted: Sat Feb 16, 2008 2:37 pm
by LuxuriousMeat
You can't write to a folder let alone open it in a FileStream so thats probably why it's giving an error.

Posted: Sat Feb 16, 2008 2:47 pm
by Aumaan Anubis
Ok, I figured it out, thanks.

But, I only know how to set it to a specific file.
How would I go about setting it to any file?

For instance...

Code: Select all

FileStream stream = new FileStream("C:\\Documents and Settings\\***** *****\\Desktop\\Test Folder\\hello.doc", FileMode.Open);
You see that the filestream goes to hello.doc.
Now, what if I want it to go to whatever file that I've opened that's within that folder?

Posted: Sat Feb 16, 2008 3:42 pm
by grimdoomer

Code: Select all

OpenFileDialog OFD = new OpenFileDialog();
if (OFD.ShowDialog() == DialogResult.Ok)
{
    FileStream FS = new FileStream(OFD.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
}