Is it possible to from my ASCX usercontrol to write to a text file either on the file system or in a sharepoint list? I tried using a streamwriter but I always get that it cant find the file Ive created.
Writing to the file system is very risky if you are in a load balanced environment as there is no guarantee that the code will be executed on the same server that wrote the file in the first place. However, even if you are on a single server environment, you will still hit deadlock/overwrite/permissions issues if two people happen to be accessing pages that contain your control at the same time.
Factor in the myriad of potential file system security issues and writing to the file system is significantly more work than it is worth.
It would be better to use a SharePoint list for this as it resolves both of the above issues. The exact code to use to write to the list would vary depending on what you are writing to the list and how (i.e. writing a file to a doclib versus attaching a file to a standard list item) In either case, I am pretty sure that you can use the MemoryStream object in order to keep everything in memory while you are preparing it to be written.