C# Access Denied

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
Aumaan Anubis




Connoisseur Bloodhound Renovator

Posts: 2938
Joined: Fri Jun 30, 2006 1:01 pm
Location: Aumaan
Contact:

C# Access Denied

Post 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?
Image
Tural wrote:MrMurder, we're going to hold you to that promise.
It is expected, and demanded.
User avatar
LuxuriousMeat





Posts: 824
Joined: Thu Nov 03, 2005 6:43 pm
Location: zzzzzzzzzzzzzzzz
Contact:

Post 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.
Image
User avatar
Aumaan Anubis




Connoisseur Bloodhound Renovator

Posts: 2938
Joined: Fri Jun 30, 2006 1:01 pm
Location: Aumaan
Contact:

Post 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?
Image
Tural wrote:MrMurder, we're going to hold you to that promise.
It is expected, and demanded.
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Post 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);
}
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
Post Reply