Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to a file on page load 1

Status
Not open for further replies.

seabaz2000

IS-IT--Management
Feb 24, 2006
79
0
0
IE
Hi
I am attempting to write to a file on page load of a particular page, but when I do so the file doesn't seem to write at all. Here is the code.
Code:
FileStream fout;

        try
        {
            fout = new FileStream("test.txt", FileMode.Create);
        }
        catch (IOException exc)
        {
            Console.WriteLine(exc.Message + "\nError Opening Output File");
            return;
        }
        try
        {
            for (char c = 'A'; c <= 'Z'; c++)
                fout.WriteByte((byte)c);
        }
        catch (IOException exc)
        {
            Console.WriteLine(exc.Message + "File Error");
        }

        fout.Close();
 
Have you checked if your security permits to create files on your application folder? If not try to add that.
Try to look for IUSR_machinename and IIS_WPG rights.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thanks for the post. I have enabled IUSR_machinename but was unable to find the usr IIS_WPG. The writing to the file still doesn't work to that folder.
Thanks for the help.
Regards
 
You could allways try to add Everyone create/write/modify file rights to a folder inside your project and test with it to track down your problems.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
I have just tried that there now and it seems to have made no difference. I have searched for that text file "text.txt" all over my harddrive and it doesn't seem to be located. The web app is built in conjunction with asp.net, not sure if this makes a difference or not.
 
Well i think you gonna need to get the file fullpath in order to create it inside your web project. Never had this problem with Windows Applications.
Try to use this
Code:
string fPath = Server.MapPath("file.txt");
//or
string fPath = Server.MapPath("file_folder/file.txt");

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top