[Mono-list] Opening a file from .aspx

Tymoteusz Majewski tymoteuszmajewski at yahoo.com.au
Sun Jul 25 21:48:14 EDT 2010


_______________________________
From: Tymoteusz Majewski <tymoteuszmajewski at yahoo.com.au>
To: Mono <mono-list at lists.ximian.com>
Sent: Tue, 20 July, 2010 7:36:30 PM
Subject: [Mono-list] Opening a file from .aspx

>
>
>
>Hello gurus,
>
>
>This is on ubuntu, Mono JIT compiler version 2.4.2.3
>
>I have mono setup which I can run c# scripts properly, but I cannot open files. 

>
>Code:
>            string file = "Config/1.txt";
>            file = Server.MapPath (file);
>            File.Open (file, FileMode.Open);
>
>Error:
>Access to the path "/MyPages/website/Config/1.txt"  is  denied.
>
>The file is accessible through apache, meaning I can go to 
>"http://192.168.1.125/Config/1.txt"; and I can read the file.
>
>If I run the same code from a mono app (not from .aspx page) it works fine.
>
>I read quite a lot about trustLevels, securityPolicy in web.config files, but 
>things just don't seem to have any effect.
>When I tried to establish the current policy level from the page itself it 
>reports as Unrestricted which is an issue on its own, but that's an issue for 
>later.
>
>I tried to find something about trust levels in mono asp but I cannot find 
>anything. 
>
>
>The bottom line is I would like to:
>a) open and read a file from within the website's directory.
>b) open and read a file from a  specified directory not in the application's 
>dir  
>(website's root dir).
>
>Thank you in advance.
>
>Thanks
>Tymek


I wasn't able to make File.Open work (even though File.Exists seems to  behave 
properly) but StreamReader reads  the files. 

StreamReader sr=new StreamReader(file);
while  (sr.Peek() >= 0) 
        sb.Append(sr.ReadLine());

Cheers
Tymek



      



More information about the Mono-list mailing list