Click here to Skip to main content
15,898,850 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, i am currently developing a GUI application and part of this application allows a user to insert a line of text in to a textfile that is located in the C drive that exists but it is supposed to append the new line, but with the code that i have come up with, it does not allow me to have access to the file but the file is not read only. i dont even know if the code that i have come up with does what it is intended to do because of this access issues. here is my code...

C#
    string newcity = txtCity.Text;
    int newfigure = int.Parse(txtSalefigure.Text);
    string filename = txtFileName.Text;

    StreamWriter file = null;
    if (File.Exists("C:/"+filename+".txt") == false)
    {
        file = new StreamWriter("C:/"+filename+".txt", true);
    }
    else
    {
        file = new StreamWriter("C:/"+filename+".txt");
    }
    file.WriteLine(newcity +"   "+newfigure+ "\n");
    file.Flush();
    file.Close();
}
Posted

1 solution

I suspect at least part of your problem might have something to do with you using a forward slash instead of a backslash in the path name.
 
Share this answer
 
Comments
morojele 28-Nov-11 13:16pm    
I HAVE CORRECTED THE SLASHES AND IT IS STILL GIVING ME THE UNAUTHORIZED ACCESS EXCEPTION

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900