Writing a text file to the file system

Discussion in 'ASP .Net' started by =?Utf-8?B?Y3dicA==?=, Mar 21, 2005.

  1. Using Visual Studio C#

    When I ran the following code:

    System.IO;

    private void Button1_Click(object sender, System.EventArgs e)
    {
    //FileStream fs = File.Create(Server.MapPath("test.txt"));
    FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt");
    StreamWriter sw = new StreamWriter(fs);
    sw.Write(TextBox1.Text);
    sw.Close();
    fs.Close();

    }

    I initially got an error message that "access was denied." The message
    suggested that I give ASP.NET user access rights/permissions to the folder.

    I then [manually] gave the logged in user write permission to the folder.

    Then, when I ran the above code, the text file was created.

    Is there another way [i.e., programatically using C#] to allow my code to
    write a text file to the file system without giving access rights to a user?
    Can the permissions be given to the app [the code] instead of to a user?

    Any suggestions would be appreciated.

    Thanks.

    bebop
     
    =?Utf-8?B?Y3dicA==?=, Mar 21, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BLF
    Replies:
    4
    Views:
    1,283
    Mike Treseler
    Aug 7, 2004
  2. HNguyen
    Replies:
    4
    Views:
    2,413
    HNguyen
    Dec 21, 2004
  3. =?Utf-8?B?Y3dicDE1?=

    Writing a text file to the file system

    =?Utf-8?B?Y3dicDE1?=, Mar 21, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    525
    shiva_ananthoju
    Oct 29, 2005
  4. icedragon
    Replies:
    0
    Views:
    651
    icedragon
    Jul 13, 2010
  5. cwbp

    Writing a text file to the file system

    cwbp, Mar 21, 2005, in forum: ASP .Net Security
    Replies:
    2
    Views:
    192
Loading...

Share This Page