Ragavan
Ragavan

Reputation: 3034

how to read file from the specificed location

if (File.Exists(Path))
{
    using (FileStream stream = new FileStream(Path, FileMode.Open))
    {
        this.LoadReport(stream);
    }
}

Path file having read only permission only. Got exception while reading, if I remove read only attribute from file properties working. How to resolve this one? Access to the path 'path' is denied. Got this exception

Upvotes: 0

Views: 72

Answers (1)

Michał Powaga
Michał Powaga

Reputation: 23183

Try define FileAccess this way:

FileStream stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read)

Added:
FileShare.Read is default so this is enough:

FileStream stream = new FileStream(Path, FileMode.Open, FileAccess.Read)

FileStream Constructor (String, FileMode, FileAccess) on MSDN.

Upvotes: 6

Related Questions