File Access in ASP.NET 2.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AlexSilverman
    New Member
    • Nov 2007
    • 2

    File Access in ASP.NET 2.0

    Hello,

    First of all, I'm somewhat new to web development, so hopefully this is easily solved.

    I've got a page hosted on an external server to which I do not have access to, and right now, I'm simply trying to append some characters to a text file based on user input to a form on that page. I'm having trouble accessing that text file. Here is the code I'm using

    string path = Page.TemplateSo urceDirectory + "Updates.tx t";
    // Open the file and add the submitted address to it
    System.IO.Strea mWriter writer = System.IO.File. AppendText(path );
    writer.Write(th is.txtEmail.Tex t);
    writer.Write("; ");
    writer.Close();

    When I run the above code on the server, I get the following error

    Security Exception
    Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security .SecurityExcept ion: Request for the permission of type 'System.Securit y.Permissions.F ileIOPermission , mscorlib, Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b77a5c561934e08 9' failed

    followed by an source error with no relevant code, and a stack trace. I'm not quite sure how I should be trying to access a file that sits alongside the cs file that's executing the code, but I'm stumped at the moment. Any help would be greatly appreciated.

    Thanks.

    - Alex
  • JamieHowarth0
    Recognized Expert Contributor
    • May 2007
    • 537

    #2
    Hi Alex, welcome to TheScripts' Developer Network!

    This is a .NET problem, particularly a C++/C#.NET problem (I noticed the .cs file extension for your underlying class file).

    I am a newbie .NET developer but in VB.NET, not in C, so I will move your thread to the .NET Forum where the .NET experts can stick their teeth into it and try and help you out.

    As you're new to TSDN, please take a couple of minutes to read our Posting Guidelines to familiarise yourself with the site etiquette and for your future reference.

    Just a quick note for yourself, this forum is intended for "classic" ASP (which is written almost exclusively in VBScript), which is why your question is better suited to the .NET Forum as it gets a better "viewing spot" for experts to review and try and help.

    Also, if you could use ['code] and ['/code] tags in future, as our forums will parse your code into pretty colours and add line numbers so it's easy for other people to read and understand your code like so:

    Code:
    'My code goes here
    Best regards,

    medicineworker

    Comment

    • AlexSilverman
      New Member
      • Nov 2007
      • 2

      #3
      Understood. Sorry for the mistakes, and thanks for relocating the post to hopefully a more helpful place :)

      - Alex

      Comment

      • JamieHowarth0
        Recognized Expert Contributor
        • May 2007
        • 537

        #4
        Hi Alex,

        Did you ever get this sorted?

        From what I know of classic ASP and how it's moved to .NET, there should be a library in ASP.NET called FileSystemObjec t which allows access to files stored on your remote web server, but I am not too sure.

        Any .NET experts help me out on this one?

        medicineworker

        Comment

        Working...